Is there a simple way to make Sequelize return it's date/time fields in a particular format?

后端 未结 4 1284
攒了一身酷
攒了一身酷 2020-12-16 00:44

We need to have sequelize return dates in a particular format, not the default one. As far as I can tell, there is no way to set that up in options, or any other way. Short

4条回答
  •  粉色の甜心
    2020-12-16 01:24

    In case of Model that we create using Sequelize CLI try something like this

               var sequelize= require('../models');
        model.findAll({
                attributes: [
                           'id',
                           'title'
               [sequelize.Sequelize.fn('date_format', sequelize.Sequelize.col('col_name'), '%d %b %y'), 'col_name']
                                ]}.then(function(result))
                                 { // dateformate=04 Nov 2017
    console.log(result)
    }
    

    visit this link for formate

提交回复
热议问题