date格式在node.JS中

我正在使用MySQL数据库,因为我有名字request_date一个字段。 该字段的types是时间戳,存储在该字段中的数据格式为2012-05-16 14:59:18 。 但是,当我通过Node.JS检索相同的数据时,数据在浏览器中显示为

 Fri Jun 08 2012 15:16:50 GMT+0530 (India Standard Time) 

为什么这种格式变化正在发生?

我写了这个查询:

 SELECT biz_registration.reqid,biz_registration.request_date,biz_registration.req_status,biz_registration.annual_cost,biz_registration.rid,biz_contact.first_name,biz_contact.last_name FROM biz_registration INNER JOIN biz_contact ON biz_registration.reqid=biz_contact.reqid ORDER BY biz_registration.request_date DESC limit '+start+','+mlimit+'' 

我正在使用的HTML代码是,

 options +='<div class="column" style="background-color: #E1E1E1;width: 100px;">'+result.reqid+'</div>'; options +='<div class="column" style="background-color: #E1E1E1;width: 160px;">'+result.request_date+'</div>'; 

我有同样的问题,这解决了我的问题:

你需要“强制”你的MySQL连接立即格式化,添加到你的configuration(连接细节):

 host: 'localhost', user: 'root' // .... dateStrings: 'date' 

我通过要求date格式的库或模块得到了这个工作。 首先我们要安装date格式包使用

npm安装dateformat

那么你可以要求在你的编码。 那么你可以创build检索数据的对象为

var day = dateFormat(result.request_date,“yyyy-mm-dd h:MM:ss”);

并打印出来。

根据node-mysql文档 ,这个configuration解决我的问题

  host: 'localhost', user: 'root', password: '', dateStrings:true, database: "mydb" 

你看到的,只是默认的JavaScriptdate格式。 如果你想要格式不同,你可以使用下面的方法:

 getDate(): Returns the date getMonth(): Returns the month getFullYear(): Returns the year 

在date对象上,并将结果与​​/或 – 或:结合,以获得所需的格式。

看看: http : //www.elated.com/articles/working-with-dates/了解更多详情