An Interest In:
Web News this Week
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
April 20, 2021 11:53 am GMT
Original Link: https://dev.to/coderslang/javascript-interview-question-34-different-ways-to-get-the-current-date-in-js-4c25
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 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 wont have any luck comparing a number
to an object
.
ANSWER: false
will be logged to the console.
Original Link: https://dev.to/coderslang/javascript-interview-question-34-different-ways-to-get-the-current-date-in-js-4c25
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To