Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is year 0 in Javascript?

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?

like image 798
thefuzzy0ne Avatar asked Mar 03 '19 13:03

thefuzzy0ne


People also ask

What is new Date () in JavaScript?

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.

What is the format of new Date ()?

const d = new Date("2015-3-25"); The behavior of "YYYY/MM/DD" is undefined.

How do I format a Date in JavaScript?

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.

What is a 0 date in JavaScript?

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 to get the current year in JavaScript?

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.

What is NewNew date in JavaScript?

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.

What is the correct date format for JavaScript?

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:


1 Answers

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.

like image 120
Jonas Wilms Avatar answered Sep 18 '22 23:09

Jonas Wilms