我正在使用 angularJs 和 moment js。我有一个发送例如
的文本框12:00 PM
到函数(apptime) - 我然后做
var newtime = moment(apptime,'hh:mm:ss');
这就是控制台输出的内容:
Thu Jan 01 1970 12:00:00 GMT+0000 (GMT Standard Time)
所以时间很好,我看到那里是 12:00:00..
然后(由于数据库结构)我想将其转换为这样:
1899-12-30 12:00:00
所以我这样做:
console.log("1899-12-30 " + newtime.format('hh:mm:ss'));
无论日期是哪一天,响应始终是
1899-12-30 01:00:00
为什么它认为 01 是时间?
最佳答案
它应该转换为 UTC 时间。
更改:
console.log("1899-12-30 " + newtime.format('hh:mm:ss'));
致:
console.log("1899-12-30 " + moment(newtime).utc().format('hh:mm:ss'));
关于javascript - Moment js 没时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37595971/