0

From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear:

The value returned by getUTCFullYear() is an absolute number that is compliant with year-2000, for example, 1995.

What does it mean to be "compliant with year-2000"?

Armand
  • 23,463
  • 20
  • 90
  • 119

3 Answers3

1
The value returned by getUTCFullYear() is an absolute number that is compliant with year-2000, for example, 1995.

This sentence mean that the number must be positive, other than 0 and it must be write for inter(compliant with year-2000, for example 1998,1999,2000, NO 98,99,00)

Ian Gallegos
  • 524
  • 1
  • 9
  • 18
0

I think "compliant with year-2000" simply means that it doesn't cause issues due to the "Y2K bug."

Simply, it means that it returns a four-digit number, not a two-digit number, so that there's no ambiguity between years in different centuries.

Sam Fen
  • 5,074
  • 5
  • 30
  • 56
0

The phrase "compliant with year-2000" is a bit misleading, and probably should be removed.

Initially, ECMAScript was implemented with a Java-like method called getYear which returned a 2 digit year that was the full year - 1900, so 1995 was returned as 95, 2017 as 117 and 1832 as -68. This method has now been moved to an appendix of ECMA-262 for web browsers only and is maintained for backward compatibility reasons, it should not be used in new code.

Although the getYear method seems a bit weird now, it was easily converted to a full year by adding 1900.

The "Y2K" issue is that 2 digit years became an issue after 1 Jan 2000 as a date like 1/1/00 would be interpreted as 1/1/1900 when 1/1/2000 was intended (and so on for any 2 digit year). This issue persists, since new Date(0,0,1) creates a date for 1/1/1900, not 1/1/0000.

That is the real year 2000 (Y2K) issue, not getting the year.

To create a date between -99 and +99, you need to set the full year, e.g. for 1 Jan 23 you need to do:

var d = new Date();
d.setFullYear(23,0,1);

In regard to getFullYear (and getUTCFullYear), it returns the full year, which can be any year that is roughly ±285,616 from 1970. It doesn't, of itself, avoid the Y2K issue. But it will return the actual year:

var d = new Date();
d.setFullYear(23, 0, 1);
console.log(d.getYear());     // -1877
console.log(d.getFullYear()); // 23
RobG
  • 142,382
  • 31
  • 172
  • 209