来自时间戳 [sqlite3, Knex] 的时间值
Time values from timestamp [sqlite3, Knex]
如何在 created_at 行中仅存储像 HH:MM 这样的 IST 时间值,从 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');
});
};
试试 date-fns
:
const dateFns = require("date-fns")
然后,在 table def:
table.timestamp('created_at').defaultTo(dateFns.format(knex.fn.now(), 'hh:mm'))
如何在 created_at 行中仅存储像 HH:MM 这样的 IST 时间值,从 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');
});
};
试试 date-fns
:
const dateFns = require("date-fns")
然后,在 table def:
table.timestamp('created_at').defaultTo(dateFns.format(knex.fn.now(), 'hh:mm'))