aurelius
aurelius

Reputation: 528

Epoch is too precise

When writing to a database I add a timestamp. But it is a bit too precise; I just want to have Year,Month,Day,Hour,Minute. Now I get the epoch down to the millisecond.

What should below be to only generate as mentioned above?

"TimeStamp": String(Date.now())

Upvotes: 0

Views: 234

Answers (1)

trincot
trincot

Reputation: 350300

You can round to the nearest minute by dividing by the number of milliseconds in a minute and multiplying that again by that factor after having rounded (or truncated) it:

Math.round(Date.now() / 60000) * 60000

Use Math.floor if you need to truncate to the minute instead of rounding to the nearest one.

Upvotes: 1

Related Questions