javascript - Convert JS date time to MySQL datetime -
does know how convert js datetime mysql datetime? there way add specific number of minutes js datetime , pass mysql datetime?
while js possess enough basic tools this, it's pretty clunky.
/** * first need create formatting function pad numbers 2 digits… **/ function twodigits(d) { if(0 <= d && d < 10) return "0" + d.tostring(); if(-10 < d && d < 0) return "-0" + (-1*d).tostring(); return d.tostring(); } /** * …and create method output date string desired. * people hate using prototypes way, if going * apply more 1 date object, having prototype * makes sense. **/ date.prototype.tomysqlformat = function() { return this.getutcfullyear() + "-" + twodigits(1 + this.getutcmonth()) + "-" + twodigits(this.getutcdate()) + " " + twodigits(this.getutchours()) + ":" + twodigits(this.getutcminutes()) + ":" + twodigits(this.getutcseconds()); };
Comments
Post a Comment