I have a string representing the current time: 2015-11-24T19:40:00
. How do I parse this string in Javascript to get a Date represented by this string as the LOCAL TIME? Due to some restriction, I cannot use the library moment
, but jquery is allowed. I know that someone has asked this question before, but the answer used moment
For example, if I run the script in California, then this string would represent 7PM pacific time, but if I run the script in NY then this string would represent Eastern Time?
I tried the following but Chrome and Firefox give me different results:
var str = 2015-11-24T19:40:00;
var date = new Date(str);
Chrome consumes it as UTC time (Tue Nov 24 2015 11:40:00 GMT-0800 (Pacific Standard Time)
),
but Firefox consumes it as my local PACIFIC time (Tue Nov 24 2015 19:40:00 GMT-0800 (Pacific Standard Time)
)
I tried adding Z to str
, like this var date = new Date(str+Z);
, then both browsers give me UTC time. Is there any similar letter to Z
which tells all browsers (at least chrome, Firefox and Safari) to parse the string as local time zone?