node.js - 使用sequelize查询出来的createdAt字段格式问题
ringa_lee
ringa_lee 2017-04-17 16:19:53
[Node.js讨论组]

使用sequelize查询出来的createdAt字段,是“Tue Mar 14 2017 16:02:21 GMT+0800 (中国标准时间)”这样的字符串。怎样恢复原有格式或者进行自定义的格式化?

ringa_lee
ringa_lee

ringa_lee

全部回复(2)
迷茫

new Date("Tue Mar 14 2017 16:02:21 GMT+0800 (中国标准时间)").getTime()

伊谢尔伦
  • 你的原有格式是啥格式? 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的话,应该没问题

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号