简体   繁体   中英

Javascript date issue on IE 7

i have a web method from which i am returning Date it is returning date like "Mon Sep 30 07:26:14 EDT 2013" now when i am converting formatt of date in my javascript code:

var d= SomeDate.format("MM/dd/yyyy hh:mm:ss tt"); //Somedate is comming from web method 

But in IE7 (09/30/2013 04:56:14 PM) it is showing wrong Time but in IE9 (09/30/2013 07:26:14 AM) its working fine.

How can we do it in IE7?

Date.format doesn't work on IE7. You can use the Date class like this :

var currentDate = new Date();
var month = currentDate.getMonth();
var day = currentDate.getDay();
month = (month < 10) ? '0' + month : month;
day = (day < 10) ? '0' + day : day;
var formatedDate = month + "/" + day + "/" + currentDate.getFullYear() + " " + currentDate.getHours() + ":" + currentDate.getMinutes() + ":" + currentDate.getSeconds();
alert (formatedDate);

Example : http://jsbin.com/enAqohO/1/edit?html,js,output

It looks like it is related to timezone. IE7 does not recognise the timezone 'EDT' in the string.

I will try moving the 'EDT' to the end of the string. Could you try

new Date("Mon Sep 30 07:26:14 2013 EDT") 

and see if it give your the right result ? Sorry, I don't have IE7 to test.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM