The user selects a date from a jquery datepicker, it has following format:
DD.MM.YYYY
When the user submits the form, I want to transform the date input to UTC using moment. However whatever I do with the input, I get a Invalid Date
error.
E.g. input is
30.03.2014
I try to format:
console.log(moment(input).format('MM/DD/YY')); <-- prints Invalid Date
I try to
console.log(moment(input).utc().toDate()); <-- prints invalid date
It seems that moment cannot parse the input, it can parse MM.DD.YY format, however the input must have DD.MM.YYYY format.
Any ideas whats wrong?
Using
moment(input, 'DD.MM.YYYY')
gives me:
{ from: '01.03.2014', to: '30.03.2014' }
{ from: Sat Mar 01 2014 00:00:00 GMT+0100 (CET),
to: Tue Apr 01 2014 11:00:00 GMT+0200 (CEST) }