【发布时间】:2015-09-29 22:02:06
【问题描述】:
我正在使用 javascript 和 Mysql 来存储日期时间
var twoDigits = function (d) {
if (0 <= d && d < 10) return "0" + d.toString();
if (-10 < d && d < 0) return "-0" + (-1 * d).toString();
return d.toString();
};
Date.prototype.toMysqlFormat = function () {
return this.getUTCFullYear() + "-" + twoDigits(1 + this.getUTCMonth()) + "-" + twoDigits(this.getUTCDate()) + " " + twoDigits(this.getUTCHours()) + ":" + twoDigits(this.getUTCMinutes()) + ":" + twoDigits(this.getUTCSeconds());
};
所以当我发送“2015-07-11 10:00:00”时,它会在 DB 中存储“2015-07-11 04:30:00”
var p = new Date("2015-07-11 10:00:00").toMysqlFormat ();
当我从数据库中检索此值时,我得到“2015-07-10T23:00:00.000Z”。
Using var x = new Date("2015-07-10T23:00:00.000Z"), it gives me
Sat Jul 11 2015 04:30:00 GMT+0530 (India Standard Time)
这里的 GMT 出错了。这是我收到的UTC时间。我的时区是 +0530
【问题讨论】:
标签: javascript mysql datetime