I have the UTC date in this format: 2015-12-09T15:44:33.737
Currently I am doing
var ts = '2015-12-09T15:44:33.737'
var localTimeString = new Date(ts).toLocaleDateString() + ", " + new Date(ts).toTimeString();
See here: http://jsbin.com/pakoxegete/1/edit?js,console
to get 12/9/2015, 10:44:33 GMT-0500 (Eastern Standard Time)
But the format I would like is
12/09/2015, 10:44:33 AM EST
The main changes I am after is ability to go from military time to standard time with AM/PM and also to be able to convert GMT-0500 (Eastern Standard Time)
to EST
. The time zones only have to work for the main timezones located in the USA.
Edit: I am interested in PST, MST, CST, EST
and their daytime counter parts: PDT, MDT, CDT, EDT
I guess the functions has more options that I expected. Was able to compromise and get this
var ts = '2015-12-09T15:44:33.737'
var options = { year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', timeZoneName: 'short' };
console.log(new Date(ts).toLocaleDateString('en-US', options));
Which results in December 9, 2015, 10:44 AM EST
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.