I am passing this new Date into both Firefox and Chrome console (same puter, and time zone) and I am getting mixed results.So confusing... In chrome new Date(); //Wed Dec 09 2015 18:06:55 GMT+0530 (IST)
In firefox new Date(); //Date 2015-12-09T12:36:34.410Z
I am passing this new Date into both Firefox and Chrome console (same puter, and time zone) and I am getting mixed results.So confusing... In chrome new Date(); //Wed Dec 09 2015 18:06:55 GMT+0530 (IST)
In firefox new Date(); //Date 2015-12-09T12:36:34.410Z
Share Improve this question asked Dec 9, 2015 at 12:56 Tanvi ShahTanvi Shah 5072 gold badges9 silver badges18 bronze badges3 Answers
Reset to default 8Your confusion is caused by different time-zones displaying.
Your Chrome gives you the time in UTC+0, while Firefox gives you the time in GMT+0530.
You can specify you want both to always be UTC by writing
var myDate = new Date();
myDate.toISOString() // will give you a date in the format you see by Chrome
What you are seeing is the result of Date.prototype.toString, which is entirely implementation dependent. So you may well see a different string in every client you test.
You can use toISOString to get an ISO 8601 format string that is UTC. There is a polyfill on MDN.
document.write(new Date().toISOString());
Firefox does not like the '-' in the string
Replace all occurrences of - with / using a regular expression and then convert the string to Date object.
var str = '01-25-2019 10:28:15 AM';
str = str.replace(/-/g,'/'); //replaces all occurances of "-"
with "/"
var dateobject = new Date(date_string);
alert(dateobject.toDateString());
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745363954a4624488.html
评论列表(0条)