Get current date/time in seconds

前端 未结 13 1660
失恋的感觉
失恋的感觉 2020-11-29 17:14

How do I get the current date/time in seconds in Javascript?

13条回答
  •  情书的邮戳
    2020-11-29 17:45

    Date.now()-Math.floor(Date.now()/1000/60/60/24)*24*60*60*1000
    

    This should give you the milliseconds from the beginning of the day.

    (Date.now()-Math.floor(Date.now()/1000/60/60/24)*24*60*60*1000)/1000
    

    This should give you seconds.

    (Date.now()-(Date.now()/1000/60/60/24|0)*24*60*60*1000)/1000
    

    Same as previous except uses a bitwise operator to floor the amount of days.

提交回复
热议问题