JavaScript Interview Question #34: Different ways to get the current date in JS

How do you prefer to get the current date in JS? What will be logged to the console?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

Both new Date() and Date.now() in JavaScript return us the current date and time.

The difference between them is…


This content originally appeared on DEV Community and was authored by Coderslang: Become a Software Engineer

js-test-34

How do you prefer to get the current date in JS? What will be logged to the console?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

Both new Date() and Date.now() in JavaScript return us the current date and time.

The difference between them is that new Date() returns the Date object and Date.now() returns the number of milliseconds elapsed from the midnight of Jan 1, 1970.

If you need to compare two dates in different formats, you can always get the number of milliseconds from any Date object using the built-in getTime() function.

Otherwise, you won’t have any luck comparing a number to an object.

ANSWER: false will be logged to the console.

Learn Full-Stack JavaScript


This content originally appeared on DEV Community and was authored by Coderslang: Become a Software Engineer


Print Share Comment Cite Upload Translate Updates
APA

Coderslang: Become a Software Engineer | Sciencx (2021-04-20T11:53:05+00:00) JavaScript Interview Question #34: Different ways to get the current date in JS. Retrieved from https://www.scien.cx/2021/04/20/javascript-interview-question-34-different-ways-to-get-the-current-date-in-js/

MLA
" » JavaScript Interview Question #34: Different ways to get the current date in JS." Coderslang: Become a Software Engineer | Sciencx - Tuesday April 20, 2021, https://www.scien.cx/2021/04/20/javascript-interview-question-34-different-ways-to-get-the-current-date-in-js/
HARVARD
Coderslang: Become a Software Engineer | Sciencx Tuesday April 20, 2021 » JavaScript Interview Question #34: Different ways to get the current date in JS., viewed ,<https://www.scien.cx/2021/04/20/javascript-interview-question-34-different-ways-to-get-the-current-date-in-js/>
VANCOUVER
Coderslang: Become a Software Engineer | Sciencx - » JavaScript Interview Question #34: Different ways to get the current date in JS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/20/javascript-interview-question-34-different-ways-to-get-the-current-date-in-js/
CHICAGO
" » JavaScript Interview Question #34: Different ways to get the current date in JS." Coderslang: Become a Software Engineer | Sciencx - Accessed . https://www.scien.cx/2021/04/20/javascript-interview-question-34-different-ways-to-get-the-current-date-in-js/
IEEE
" » JavaScript Interview Question #34: Different ways to get the current date in JS." Coderslang: Become a Software Engineer | Sciencx [Online]. Available: https://www.scien.cx/2021/04/20/javascript-interview-question-34-different-ways-to-get-the-current-date-in-js/. [Accessed: ]
rf:citation
» JavaScript Interview Question #34: Different ways to get the current date in JS | Coderslang: Become a Software Engineer | Sciencx | https://www.scien.cx/2021/04/20/javascript-interview-question-34-different-ways-to-get-the-current-date-in-js/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.