Json Date to JavasScript Date Conversion problem
Heres the code for converting the json retured date to a string of date.
String.toDate = function(stringDate) {
var newDate = new Date(parseInt(stringDate.replace("/Date(", "").replace(")/", ""), 10));
return newDate;
}
Here are the details:
Date from the database: 2009-11-18 03:23:25.107 Date Returned by JSON: "/Date(1258514605107)/" Date Returned by the toDate function : Wed Nov 18 2009 11:23:25 GMT+0800 (Taipei Standard Time)
开发者_开发问答Web Server and Database server time zone are the same.
Im wondering why the date becomes the current date in my timezone. Is there anyone here encountered this kind of problem?
and what about your browser/OS settings ? you need the GMT time ?
I think you get get it with toUTCString a more complete reference about the date class
alert(newDate.toUTCString());
精彩评论