我在使用 momentjs 库获得正确的日期时间时遇到了一些困难。
我正在做这个
****--------- Datetime ----------****
Timestamp received from database -> 2016-07-12 17:21:40 <- THIS IS A UTC DATE TIME
moment.tz(datetime, moment.tz.guess()); //datetime value is '2016-07-12 17:21:40' and moment.tz.guess() is returning "America/Sao_Paulo"
// inspect the moment object returned
q{ _isAMomentObject:true, _i:"2016-07-12 17:21:40", _f:"YYYY-MM-DD HH:mm:ss", _isUTC:true, _pf:Object…}
_a: Array[7]
_d:Tue Jul 12 2016 14:21:40GMT-0300 (BRT) <- THIS IS THE CORRECT DATE TIME THAT I WANT
_f:"YYYY-MM-DD HH:mm:ss"
_i:"2016-07-12 17:21:40"
_isAMomentObject:true
_isUTC:true
_isValid:true
_locale:B
_offset:-180
_pf:Object
_z:h
__proto__:Object
// moment object formatted .format('YYYY-MM-DD HH:mm:ss')
2016-07-12 17:21:40 <- THIS IS THE DATE TIME THAT I'M GETTING, AND IT IS WRONG
****-------------------****
我不知道我在这里做错了什么。
答案 0 :(得分:0)
解决方案:
我发现了如何存档。
moment.tz(moment.utc(datetime), moment.tz.guess());