Friday 31 May 2024

javascript convert UTC date time string Z to local

 https://stackoverflow.com/questions/6525538/convert-utc-date-time-to-local-date-time


Options 2: If UTC date format is ISO-8601. Mostly servers timestampz format are in ISO-8601 ex: '2011-06-29T16:52:48.000Z'. With this we can just pass it to the date function and toLocaleString() function.

let newDate = "2011-06-29T16:52:48.000Z"
new Date(newDate).toLocaleString();
//output: 6/29/2011, 4:52:48 PM


JS new date
will intake string if no timezone treat as it is in user local time
or timezone string

convert both to browser time zone:

https://www.w3schools.com/js/js_dates.asp

No comments:

Post a Comment