javascript - How can I convert a UTC date to ISOString format without changing the date/time? -
here's code have far. current utc time = 1:22pm
var = new date(); var now_utc = new date(now.getutcfullyear(), now.getutcmonth(), now.getutcdate(), now.getutchours(), now.getutcminutes(), now.getutcseconds()); var isodate1 = now_utc.toisostring(); >>> wed jul 06 2016 21:22:20 gmt+0800 now_utc >>> wed jul 06 2016 13:22:20 gmt+0800 (malay peninsula standard time) isodate1 >>> "2016-07-06t05:22:20.000z"
my problem expected , need, isodate1 this:
2016-07-06t13:22:20.000z
it seems now_utc correct when converted iso format changes.
can give me advice on this?
new date(...)
construct date/time passed being local time, , toisostring
gives both iso format, utc equivalent of local time constructed, hence behaviour you're seeing - note how output of now_utc
showing gmt+0800
- means it's local time, offset gmt/utc +8 hours.
you should able current utc time iso string:
(new date()).toisostring(); //"2016-07-06t13:39:50.432z"
Comments
Post a Comment