【发布时间】:2018-11-14 22:08:47
【问题描述】:
我以为我了解如何将存储在我们数据库中的时间转换为用户本地时间,但似乎我不了解。当我将启动时间保存到我的 postresql 数据库(在 Heroku 上)时,它以 2018-11-14 19:45:00 的形式提供,我将它保存为 TIMESTAMP。在我保存它的时候我应该使用时刻吗?
运行 Heroku 日志我注意到服务器时间是2018-11-14T19:45:00.200076+00:00,也就是 UTC?
在我的节点应用程序中使用 moment JS 我正在执行以下操作
fixture.kick_off = 2018-11-14 19:45:00.000000
<%= moment(fixture.kick_off).local().format('HH:mm A') %>
我有一个来自丹麦的用户说这显示为晚上 19:45,而我希望它根据时差显示为晚上 20:45
我在这里误解了什么(很可能)
谢谢
更新
我现在根据马特的回答使用以下内容
<%= moment.utc(fixture.kick_off).local().format('HH:mm A') %>
继马特关于检查 typeof fixture.kick_off 的评论之后,它返回 object,现在已将我的代码更新为
<% var kick_off = fixture.kick_off.toString() %>
<%= moment.utc(kick_off).local().format('HH:mm') %>
在控制台中返回以下内容
Deprecation warning: value provided is not in a recognized RFC2822 or ISO
format. moment construction falls back to js Date(), which is not reliable
across all browsers and versions. Non RFC2822/ISO date formats are discouraged
and will be removed in an upcoming major release. Please refer to
http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:
[0] _isAMomentObject: true, _isUTC: true, _useUTC: true, _l: undefined, _i: Thu
Nov 15 2018 19:00:00 GMT+0000 (Greenwich Mean Time), _f: undefined, _strict:
undefined, _locale: [object Object]
Error
【问题讨论】: