【发布时间】:2022-01-18 06:30:13
【问题描述】:
我有这个:
let currentTS = Math.floor(+new Date() / 1000)
它有效,它在unix timestamp 中为我提供了当前日期。但现在我想在 unix 时间戳上加上 14 天。
如何将 14 天添加到 unix 时间戳,并返回添加了 14 天的 unix 时间戳?
【问题讨论】:
-
如果您不是故意尝试进行日期数学,我会使用 moment 或 luxon,它比手动数学更容易使用:momentjs.com。您将能够执行
moment().add(14, 'days')之类的操作 -
@dufox——甚至是authors of moment.js recommends not using moment.js。您应该使用非单体库,例如 date-fns 或 dayjs。
标签: javascript node.js unix unix-timestamp