Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert the (fractional) result of `new Date().getTime() / 1000` into a whole number?

According to this: Get current date/time in seconds

var seconds = new Date().getTime() / 1000; gives you the time in seconds. But the time given is a decimal number. How can I turn it into whole number?

like image 739
jQuerybeast Avatar asked Sep 03 '25 05:09

jQuerybeast


1 Answers

You do Math.round(new Date().getTime() / 1000) or a short (and faster version):

new Date().getTime() / 1000 | 0

Using this binary operator will zero the floating number part of your number (and therefore round it down).

like image 181
copy Avatar answered Sep 04 '25 22:09

copy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!