javascript - Getting the timezone a simplified ISO 8601 date string -
i have 2 date strings, each in different time zone. these strings in believe referred "simplified" iso 8601 format. 2 example dates listed below.
2017-08-14t18:41:52.793z2017-08-14t23:41:52.000z
the first date in cdt while second date in utc. believe last 4 digits of each of these strings indicates time zone.
what's weird when set new date() each of these, i'm getting incorrect dates reported via console.log(). example:
const local_date = new date("2017-08-14t18:41:52.793z"); const remote_date = new date("2017-08-14t23:41:52.000z"); console.log("local_date = " + local_date); console.log("remote_date = " + remote_date); outputs:
local_date = mon aug 14 2017 13:41:52 gmt-0500 (central daylight time)
remote_date = mon aug 14 2017 18:41:52 gmt-0500 (central daylight time)
it appears though first date getting 5 hours subtracted though source date provided in cdt; it's it's assuming both dates provided in utc.
https://jsfiddle.net/nkax7cjx/1/
what don't wrong here?
the last 4 digits 3 digit milliseconds followed timezone, z indicates utc time, , +hh:mm , -hh:mm indicates offset utc time.
so 793z 793 milliseconds in utc.
so both of examples in utc, why you're seeing output you're seeing.
const local_date = new date("2017-08-14t18:41:52.793-05:00"); would cdt format.
Comments
Post a Comment