How to parse a date in the dd.mm.yyyy format?

1.2k Views Asked by At

I try to parse a date in the dd.mm.yyyyformat: Globalize.parseDate(value, "dd.MM.yyyy", "en"); but globalize crashes with errors:

Uncaught Error: E_INVALID_PAR_TYPE: Invalid options parameter (dd.mm.yyyy). Plain Object expected.
at createError (globalize.js:105)
at validate (globalize.js:182)
at validateParameterType (globalize.js:257)
at validateParameterTypePlainObject (globalize.js:295)
at Function.Globalize.dateParser.Globalize.dateParser (date.js:1853)
at Function.Globalize.parseDate.Globalize.parseDate (date.js:1908)
at $.validator.methods.date (Index:1891)
at $.validator.check (jquery.validate.js:759)
at $.validator.checkForm (jquery.validate.js:450)

Linked script files:

<script src="/Scripts/cldr.js"></script>
<script src="/Scripts/globalize.js"></script>
<script src="/Scripts/globalize/message.js"></script>
<script src="/Scripts/globalize/number.js"></script>
<script src="/Scripts/globalize/date.js"></script>

How can I fix it?

1

There are 1 best solutions below

3
On BEST ANSWER

You need to pass the function a value and then an options object.

Globalize.locale('en');
Globalize.parseDate(value, {
    skeleton: 'dd.MM.yyyy'
});

You can find the documentation for this here.