new Date vs Date.now() | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

22nd Jan 2022, 6:36 AM
EsaKurniawan
1 Answer
+ 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.
22nd Jan 2022, 7:02 AM
Ankita Kumari
Ankita Kumari - avatar