thefuzzy0ne
thefuzzy0ne

Reputation: 481

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?

Upvotes: 8

Views: 1604

Answers (1)

Jonas Wilms
Jonas Wilms

Reputation: 138457

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.

Upvotes: 4

Related Questions