【发布时间】:2014-04-01 10:38:52
【问题描述】:
用户从 jquery datepicker 中选择一个日期,格式如下:
DD.MM.YYYY
当用户提交表单时,我想使用 moment 将日期输入转换为 UTC。但是,无论我对输入做什么,都会收到 Invalid Date 错误。
例如输入是
30.03.2014
我尝试格式化:
console.log(moment(input).format('MM/DD/YY')); <-- prints Invalid Date
我试试
console.log(moment(input).utc().toDate()); <-- prints invalid date
好像moment不能解析输入,可以解析MM.DD.YY格式,但是输入必须是DD.MM.YYYY格式。
有什么想法吗?
使用
moment(input, 'DD.MM.YYYY')
给我:
{ 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) }
【问题讨论】:
标签: javascript node.js momentjs