开发者

Json Date to JavasScript Date Conversion problem

开发者 https://www.devze.com 2022-12-11 14:05 出处:网络
Heres the code for converting the json retured date to a string of date. String.toDate = function(stringDate) {

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());
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号