Take the following code
var d = new Date();
d.setFullYear(0);
alert(d);
What year is year 0000? After all, year 0 isn't actually a thing, since we went from 1BC to 1AD. Is year 0 actually 1BC and year -1 actually 2BC?
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.
const d = new Date("2015-3-25"); The behavior of "YYYY/MM/DD" is undefined.
Standard ECMAScript formatting functions: Since more recent versions of ECMAScript, the Date class has some specific formatting functions: toDateString: Implementation dependent, show only the date. toISOString: Show ISO 8601 date and time.
Date strings are described in the next chapter. JavaScript stores dates as number of milliseconds since January 01, 1970, 00:00:00 UTC (Universal Time Coordinated). Zero time is January 01, 1970 00:00:00 UTC. new Date ( milliseconds) creates a new date object as zero time plus milliseconds:
How Get the Current Year in JavaScript. To get the current year, you can call the getFullYear () method will return the year of the specified Date according to local time. The value returned by is an absolute number. For the dates between 1000 and 9999 years, the getFullYear () method returns a four-digit number.
new Date (dateString) creates a new date object from a date string: Date strings are described in the next chapter. JavaScript stores dates as number of milliseconds since January 01, 1970, 00:00:00 UTC (Universal Time Coordinated). Zero time is January 01, 1970 00:00:00 UTC.
JavaScript ISO Dates ISO 8601 is the international standard for the representation of dates and times. The ISO 8601 syntax (YYYY-MM-DD) is also the preferred JavaScript date format:
The ES262 specification says:
20.3.1.3 Year Number
ECMAScript uses a proleptic Gregorian calendar to map a day number to a year number and to determine the month and date within that year.
If you look up proleptic Gregorian calendar on Wikipedia, you'll find:
For these calendars one can distinguish two systems of numbering years BC. Bede and later historians did not use the Latin zero, nulla, as a year (see Year zero), so the year preceding AD 1 is 1 BC. In this system the year 1 BC is a leap year (likewise in the proleptic Julian calendar). Mathematically, it is more convenient to include a year 0 and represent earlier years as negative, for the specific purpose of facilitating the calculation of the number of years between a negative (BC) year and a positive (AD) year.
Therefore it is up to your interpretation wether year 0 exists or not.
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