I have a date 2018-06-19 09:06:29
. It is how it is stored in the database. I am using moment-timezone
and calling this function.
function getDateString(t, tz) {
return moment()
.tz("America/Chicago")
.format('l');
}
Here I know that my timezone
is "America/Chicago" and it is "UTC-5 hours". I should get the time 5 hours before the time that I have passed as an argument.
This function was working perfectly until I upgraded my react. Can anyone know what might be the issue?
These are my current settings of react
"expo": "^27.0.0",
"moment": "^2.22.2",
"react": "16.3.1",
"react-moment": "^0.7.0",
"moment-timezone": "^0.5.17",
"react-native": ".0.0.tar.gz",
"react-native-swipeable": "^0.6.0",
"react-navigation": "1.5.11"
I have a date 2018-06-19 09:06:29
. It is how it is stored in the database. I am using moment-timezone
and calling this function.
function getDateString(t, tz) {
return moment()
.tz("America/Chicago")
.format('l');
}
Here I know that my timezone
is "America/Chicago" and it is "UTC-5 hours". I should get the time 5 hours before the time that I have passed as an argument.
This function was working perfectly until I upgraded my react. Can anyone know what might be the issue?
These are my current settings of react
"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./expo/react-native/archive/sdk-27.0.0.tar.gz",
"react-native-swipeable": "^0.6.0",
"react-navigation": "1.5.11"
Share
Improve this question
edited Jun 19, 2018 at 12:14
Pac0
23.3k9 gold badges73 silver badges83 bronze badges
asked Jun 19, 2018 at 10:27
Ali ZiaAli Zia
3,8755 gold badges33 silver badges82 bronze badges
2
-
"This function was working perfectly" it seems to me that this function is not doing anything with what I guess is your date/time argument
t
– Pac0 Commented Jun 19, 2018 at 11:12 - also, please give exact output you get, and the one you used to get, there are often some confusions about what a date time is as data, and how it is represented as string / message, with all the fancy timezone and locale stuff – Pac0 Commented Jun 19, 2018 at 11:14
1 Answer
Reset to default 4As per my ments, not sure exactly what is going wrong (and how it used to work on your side), but here is how it should work to me :
Create a moment with your date time, specifying that this is expressed as utc, with
moment.utc()
convert it to your timezone with
moment.tz()
This would give something like :
function getDateString(t, tz) {
return moment.utc(t, 'YYYY-MM-DD HH:mm:ss')
.tz("America/Chicago")
.format('l');
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745156071a4614127.html
评论列表(0条)