Datetime conversion in Mysql and javascript -
i using javascript , mysql store datetime
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()); };
so when send "2015-07-11 10:00:00" stores "2015-07-11 04:30:00" in db
var p = new date("2015-07-11 10:00:00").tomysqlformat ();
when retrieve value db "2015-07-10t23:00:00.000z".
using var x = new date("2015-07-10t23:00:00.000z"), gives me sat jul 11 2015 04:30:00 gmt+0530 (india standard time)
gmt here coming wrong. utc time receiving. time zone +0530
try adding below in "my.cnf" file zone u need
default_time_zone='+05:30' or '+00:00'
or
timezone='utc' or 'gmt'
http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html
Comments
Post a Comment