Reputation: 528
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
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