我用的是天使和瞬间的js。例如,我有一个文本框
下午12:00
函数(apptime) -然后我执行
var newtime = moment(apptime,'hh:mm:ss');这就是控制台输出的内容:
Thu Jan 01 1970 12:00:00 GMT+0000 (GMT Standard Time)时间到了,我看到那里12点.
然后(由于数据库结构),我想将其转换为:
1899-12-30 12:00
所以我就这么做:
console.log("1899-12-30 " + newtime.format('hh:mm:ss'));不管日期是什么时候,回应总是
1899-12-30 01:00:00
为什么它认为01是时间?
发布于 2016-06-02 15:34:08
它应该转换为UTC时间。
更改:
console.log("1899-12-30 " + newtime.format('hh:mm:ss'));至:
console.log("1899-12-30 " + moment(newtime).utc().format('hh:mm:ss'));发布于 2016-06-02 15:59:49
尝尝这个。moment.js的输入格式不正确。
var apptime = '12:00 PM';
var newtime = moment(apptime,'hh:mm a');
console.log(apptime);
console.log(newtime);
console.log("1899-12-30 " + newtime.format('HH:mm:ss'));我还修改了输出格式,使之成为军事时间,但如果您愿意,可以将其修改为基本的AM/PM。
https://stackoverflow.com/questions/37595971
复制相似问题