+ 1
new Date vs Date.now()
What difference in bellow code when i use Date.now and when i wasn't using it Is using both approach will give same results, or maybe give slite different at some point? https://code.sololearn.com/WfSWEFmt0Nll/?ref=app
1 Antwort
+ 4
• new Date() - creates a Date object representing the current date/time
• Date.now() - returns the number of milliseconds since midnight 01 January, 1970 UTC
As a matter of style, I found it clearer to use Date.now() in code that deals with intervals (usually subtracting an earlier date from a later date to calculate the time elapsed), and new Date() for timestamps, e.g. those written to a database.