我正在使用knexjs,我以YYYY-MM-DD HH:mm:ss例如2017-07-14 15:00:00的格式插入数据,并且在保存数据后保存时,将datetime列值作为javasript Date对象返回. 我想以YYYY-MM-DD HH:mm:ss格式返回那些对象,但以YYYY-MM-DDTHH:mm:ss.000Z格式返回,例如2017-06-23T06:44:44.000Z. 我通过迭代和手动转换它们来返回它们.我想知道是否还有另一种方式可以做到,例如在mysql驱动程序或knexjs配置中.目前,我的knexjs配置是这个.
i am using knexjs i insert data in the format YYYY-MM-DD HH:mm:ss e.g 2017-07-14 15:00:00 and after saving when the data is fetched the datetime column values are returned as javasript Date object. i want to return those object in the format YYYY-MM-DD HH:mm:ss but it returning in the format YYYY-MM-DDTHH:mm:ss.000Z e.g 2017-06-23T06:44:44.000Z. i am returning them by iterating and converting them manually. i was wondering if there is another way to do it like in mysql driver or knexjs configuration. currently my knexjs configuration is this.
var connection = require('knex')({ client: 'mysql', connection: { host: db.host, user: db.user, password: db.password, database: db.database, timezone: 'UTC' } });推荐答案
使用以下方法更改连接对象:
Change your connection object with this:
var connection = require('knex')({ client: 'mysql', connection: { host: db.host, user: db.user, password: db.password, database: db.database, timezone: 'UTC', dateStrings: true } });更多推荐
Knexjs返回mysql时间戳,datetime列作为Javascript Date对象
发布评论