84669 人が学習中
152542 人が学習中
20005 人が学習中
5487 人が学習中
7821 人が学習中
359900 人が学習中
3350 人が学習中
180660 人が学習中
48569 人が学習中
18603 人が学習中
40936 人が学習中
1549 人が学習中
1183 人が学習中
32909 人が学習中
使用sequelize查询出来的createdAt字段,是“Tue Mar 14 2017 16:02:21 GMT+0800 (中国标准时间)”这样的字符串。怎样恢复原有格式或者进行自定义的格式化?
ringa_lee
new Date("Tue Mar 14 2017 16:02:21 GMT+0800 (中国标准时间)").getTime()
你的原有格式是啥格式? YYYY-MM-DD HH:mm:ss ???
YYYY-MM-DD HH:mm:ss
const model = sequelize.define('model', {//columns specifications createdAt: { type : TYPE.DATE, allowNull : false, get() { const createAt = this.getDataValue('createAt') // createAt is an instance of date, you could operate it with moment library // to get ur format return createAt }, set(createAt) { return this.setDataValue('createAt',createAt) } } }, { // options timestamps: true // the createdAt and updatedAt will be stored by YYYY-MM-DD HH:mm:ss });
如果你对数据库进行crud的操作都是通过sequelize的话,应该没问题
new Date("Tue Mar 14 2017 16:02:21 GMT+0800 (中国标准时间)").getTime()
你的原有格式是啥格式?
YYYY-MM-DD HH:mm:ss
???如果你对数据库进行crud的操作都是通过sequelize的话,应该没问题