Reputation: 1649
I am trying to convert a localized datetime string to unix time in moment.js, but to no avail. Does anyone know a workaround to do this?
moment.locale('de');
var a = moment('20.06.2015').format("X"); //returns Invalid Date
var b = moment('20.06.2015').unix(); //returns Invalid Date
Upvotes: 1
Views: 1351
Reputation: 241959
Always supply a format when you parse.
moment.locale('de');
var a = moment('20.06.2015', 'DD.MM.YYYY').unix();
If you want, you can use the locale-defined formats. For German, the L
format is DD.MM.YYYY
.
moment.locale('de');
var a = moment('20.06.2015', 'L').unix();
This is useful if you might change locales and want the format to change to match.
Upvotes: 1