【发布时间】:2017-09-26 07:14:16
【问题描述】:
我正在尝试使用moment.js 将存储在数据库中的日期(设置为Europe/London 时区)与当前用户时间进行比较,同时考虑到他们的时区。
我得到一个从数据库返回的日期字符串,想使用fromNow()函数,如下:
console.log(dbDate);
console.log(moment().format());
console.log(moment(dbDate).fromNow());
// DB stored time (Europe/London)
// 2017-09-26 06:56:26
// Current user time (timezone is Pacific Time / Los Angeles)
// 2017-09-25T23:59:03-07:00
// String output by fromNow() function, which should reflect the timezone difference but doesn't
// in 7 hours
我希望fromNow() 字符串考虑时区差异,这应该始终是时间"ago",而不是将来。
我可能在库中遗漏了一些非常明显的东西,所以如果这很简单,请提前道歉。
【问题讨论】:
标签: javascript jquery momentjs