My eyes must be deceiving me, but when I call setMonth(1)
shouldn't the date of that date object be February? (Today is March 30, 2016)
x = new Date();
y = new Date();
x.setMonth(1);
document.write(x.toString() + '<br>' + y.toString());
Results in:
If you instead want to get the current time stamp, you can create a new Date object and use the getTime() method. const currentDate = new Date(); const timestamp = currentDate. getTime(); In JavaScript, a time stamp is the number of milliseconds that have passed since January 1, 1970.
The Date object is an inbuilt datatype of JavaScript language. It is used to work with dates and times. The Date object is created by using new keyword, i.e. new Date(). The Date object can be used date and time in terms of millisecond precision within 100 million days before or after 1/1/1970.
There is no February 30, 2016
So therefore the date processor correctly changes the date to March 1, 2016
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With