简体   繁体   English

来自时间戳 [sqlite3, Knex] 的时间值

[英]Time values from timestamp [sqlite3, Knex]

How can i store only IST time values like HH:MM in created_at row, values generated from timestamp are in UTC and DATE+TIME format如何在 created_at 行中仅存储 IST 时间值(如 HH:MM),从timestamp生成的值采用 UTC 和 DATE+TIME 格式

exports.up = function(knex) {
    return knex.schema.createTable('tbl_xyz', (table) => {
        table.increments('id').primary();
        table.timestamp('created_at').defaultTo(knex.fn.now());
        table.string('date');
        table.string('url');
        table.string('tags');
    });
};

Try with date-fns :尝试使用date-fns

const dateFns = require("date-fns")

Then, on table def:然后,在表 def 上:

table.timestamp('created_at').defaultTo(dateFns.format(knex.fn.now(), 'hh:mm'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM