Search code examples
javascriptnode.jsunixunix-timestamp

How to add x days to unix timestamp


I have this:

let currentTS = Math.floor(+new Date() / 1000)

and it works, it gives me the current date in a unix timestamp. But now I want to add 14 days to the unix timestamp.

How can I add 14 days to the unix timestamp, and return the unix timestamp with 14 days added to it?


Solution

  • Just compute how many seconds are in 14 days and add it?

    Math.floor(+new Date() / 1000) + 14 * 24 * 60 * 60