我有一个约会2018-06-19 09:06:29
。它是如何存储在数据库中的。我正在使用moment-timezone
并调用此函数。
function getDateString(t, tz) {
return moment()
.tz("America/Chicago")
.format('l');
}
我知道我的timezone
是"美国/芝加哥"它是" UTC-5小时"。我应该在我作为一个论点过去的时间前5小时得到时间。
此功能完美运行,直到我升级了反应。任何人都可以知道可能是什么问题吗?
这些是我当前的反应设置
"expo": "^27.0.0",
"moment": "^2.22.2",
"react": "16.3.1",
"react-moment": "^0.7.0",
"moment-timezone": "^0.5.17",
"react-native": "https://github.com/expo/react-native/archive/sdk-27.0.0.tar.gz",
"react-native-swipeable": "^0.6.0",
"react-navigation": "1.5.11"
答案 0 :(得分:4)
根据我的评论,不确定到底出了什么问题(以及它过去如何在您的身边工作),但是这就是它应该如何对我起作用:
用日期时间创建时刻,并用moment.utc()
使用moment.tz()
这将给出类似的内容:
function getDateString(t, tz) {
return moment.utc(t, 'YYYY-MM-DD HH:mm:ss')
.tz("America/Chicago")
.format('l');
}