node.js - Wrong time format fetched -
i using node fetching data mysql. in database, got record : 2013-08-13 15:44:53 . when node fetches database , assigns value 2013-08-19t07:54:33.000z.
i need time format in mysql table. btw ( column format datetime in mysql)
in node :
connection.query(post, function(error, results, fields) { usersocket.emit('history :', { 'datamode': 'history', msg: results, }); });
when retrieving database date object exactly should work with (strings display dates, working on string representation of date nothing want do).
if need string representation, create based on data stored in date
object - or better, library adds proper strftime
-like method prototype.
the best choice such library moment.js allows string format want:
moment('2013-08-19t07:54:33.000z').format('yyyy-mm-dd hh:mm:ss') // output (in case on system using utc+2 local timezone): // "2013-08-19 09:54:33"
however, when sending through socket (which requires string representation) it's idea use default 1 since can pass new date(..)
constructor on client side , proper date
object again.
Comments
Post a Comment