recursal/MDN huggingface dataset:
Date.prototype.getFullYear()
============================

The **`getFullYear()`** method of `Date` instances returns the year for this date according to local time.

Use this method instead of the `getYear()` method.

Try it
------

Syntax
------


```js
getFullYear()
```

### Parameters

None.

### Return value

An integer representing the year for the given date according to local time. Returns `NaN` if the date is invalid.

Description
-----------

Unlike `getYear()`, the value returned by `getFullYear()` is an absolute number. For dates between the years 1000 and 9999, `getFullYear()` returns a four-digit number, for example, 1995. Use this function to make sure a year is compliant with years after 2000.

Examples
--------

### Using getFullYear()

The `fullYear` variable has value `1995`, based on the value of the `Date` object `xmas95`.


```js
const xmas95 = new Date("1995-12-25T23:15:30");
const fullYear = xmas95.getFullYear();

console.log(fullYear); // 1995
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.getfullyear |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Date.prototype.getUTCFullYear()`
* `Date.prototype.setFullYear()`
* `Date.prototype.getYear()`
Date.prototype.setUTCMonth()
============================

The **`setUTCMonth()`** method of `Date` instances changes the month and/or day of the month for this date according to universal time.

Try it
------

Syntax
------


```js
setUTCMonth(monthValue)
setUTCMonth(monthValue, dateValue)
```

### Parameters

`monthValue`

An integer representing the month: 0 for January, 1 for February, and so on.

`dateValue` Optional

An integer from 1 to 31 representing the day of the month.

### Return value

Changes the `Date` object in place, and returns its new timestamp. If a parameter is `NaN` (or other values that get coerced to `NaN`, such as `undefined`), the date is set to Invalid Date and `NaN` is returned.

Description
-----------

 If you do not specify the `dateValue` parameter, the value returned from the
 `getUTCDate()` method is used.

 If a parameter you specify is outside of the expected range, `setUTCMonth()`
 attempts to update the date information in the `Date` object accordingly.
 For example, if you use 15 for `monthValue`, the year will be incremented by
 1, and 3 will be used for month.

Examples
--------

### Using setUTCMonth()


```js
const theBigDay = new Date();
theBigDay.setUTCMonth(11);
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.setutcmonth |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Date.prototype.getUTCMonth()`
* `Date.prototype.setMonth()`
Date.prototype[@@toPrimitive]()
===============================

The **`[@@toPrimitive]()`** method of `Date` instances returns a primitive value representing this date. It may either be a string or a number, depending on the hint given.

Try it
------

Syntax
------


```js
date[Symbol.toPrimitive](hint)
```

### Parameters

`hint`

A string representing the type of the primitive value to return. The following values are valid:

* `"string"` or `"default"`: The method should return a string.
* `"number"`: The method should return a number.

### Return value

If `hint` is `"string"` or `"default"`, this method returns a string by coercing the `this` value to a string (first trying `toString()` then trying `valueOf()`).

If `hint` is `"number"`, this method returns a number by coercing the `this` value to a number (first trying `valueOf()` then trying `toString()`).

### Exceptions

`TypeError`

Thrown if the `hint` argument is not one of the three valid values.

Description
-----------

The `[@@toPrimitive]()` method is part of the type coercion protocol. JavaScript always calls the `[@@toPrimitive]()` method in priority to convert an object to a primitive value. You rarely need to invoke the `[@@toPrimitive]()` method yourself; JavaScript automatically invokes it when encountering an object where a primitive value is expected.

The `[@@toPrimitive]()` method of the `Date` object returns a primitive value by either invoking `this.valueOf()` and returning a number, or invoking `this.toString()` and returning a string. It exists to override the default primitive coercion process to return a string instead of a number, because primitive coercion, by default, calls `valueOf()` before `toString()`. With the custom `[@@toPrimitive]()`, `new Date(0) + 1` returns `"Thu Jan 01 1970 00:00:00 GMT+0000 (Coordinated Universal Time)1"` (a string) instead of `1` (a number).

Examples
--------

### Using [@@toPrimitive]()


```js
const d = new Date(0); // 1970-01-01T00:00:00.000Z

d[Symbol.toPrimitive]("string"); // "Thu Jan 01 1970 00:00:00 GMT+0000 (Coordinated Universal Time)"
d[Symbol.toPrimitive]("number"); // 0
d[Symbol.toPrimitive]("default"); // "Thu Jan 01 1970 00:00:00 GMT+0000 (Coordinated Universal Time)"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype-@@toprimitive |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Symbol.toPrimitive`
Date.prototype.valueOf()
========================

The **`valueOf()`** method of `Date` instances returns the number of milliseconds for this date since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC.

Try it
------

Syntax
------


```js
valueOf()
```

### Parameters

None.

### Return value

A number representing the timestamp, in milliseconds, of this date. Returns `NaN` if the date is invalid.

Description
-----------

The `valueOf()` method is part of the type coercion protocol. Because `Date` has a `[@@toPrimitive]()` method, that method always takes priority over `valueOf()` when a `Date` object is implicitly coerced to a number. However, `Date.prototype[@@toPrimitive]()` still calls `this.valueOf()` internally.

The `Date` object overrides the `valueOf()` method of `Object`. `Date.prototype.valueOf()` returns the timestamp of the date, which is functionally equivalent to the `Date.prototype.getTime()` method.

Examples
--------

### Using valueOf()


```js
const d = new Date(0); // 1970-01-01T00:00:00.000Z
console.log(d.valueOf()); // 0
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.valueof |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Object.prototype.valueOf()`
* `Date.prototype.getTime()`
Date.prototype.setUTCSeconds()
==============================

The **`setUTCSeconds()`** method of `Date` instances changes the seconds and/or milliseconds for this date according to universal time.

Try it
------

Syntax
------


```js
setUTCSeconds(secondsValue)
setUTCSeconds(secondsValue, msValue)
```

### Parameters

`secondsValue`

An integer between 0 and 59 representing the seconds.

`msValue` Optional

An integer between 0 and 999 representing the milliseconds.

### Return value

Changes the `Date` object in place, and returns its new timestamp. If a parameter is `NaN` (or other values that get coerced to `NaN`, such as `undefined`), the date is set to Invalid Date and `NaN` is returned.

Description
-----------

 If you do not specify the `msValue` parameter, the value returned from the
 `getUTCMilliseconds()` method is
 used.

 If a parameter you specify is outside of the expected range,
 `setUTCSeconds()` attempts to update the date information in the
 `Date` object accordingly. For example, if you use 100 for
 `secondsValue`, the minutes stored in the `Date` object will be
 incremented by 1, and 40 will be used for seconds.

Examples
--------

### Using setUTCSeconds()


```js
const theBigDay = new Date();
theBigDay.setUTCSeconds(20);
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.setutcseconds |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Date.prototype.getUTCSeconds()`
* `Date.prototype.setSeconds()`
Date.prototype.toISOString()
============================

The **`toISOString()`** method of `Date` instances returns a string representing this date in the date time string format, a *simplified* format based on ISO 8601, which is always 24 or 27 characters long (`YYYY-MM-DDTHH:mm:ss.sssZ` or `±YYYYYY-MM-DDTHH:mm:ss.sssZ`, respectively). The timezone is always UTC, as denoted by the suffix `Z`.

Try it
------

Syntax
------


```js
toISOString()
```

### Parameters

None.

### Return value

A string representing the given date in the date time string format according to universal time. It's the same format as the one required to be recognized by `Date.parse()`.

### Exceptions

`RangeError`

Thrown if the date is invalid or if it corresponds to a year that cannot be represented in the date string format.

Examples
--------

### Using toISOString()


```js
const d = new Date(0);

console.log(d.toISOString()); // "1970-01-01T00:00:00.000Z"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.toisostring |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Date.prototype.toLocaleDateString()`
* `Date.prototype.toString()`
* `Date.prototype.toUTCString()`
Date.prototype.toUTCString()
============================

The **`toUTCString()`** method of `Date` instances returns a string representing this date in the RFC 7231 format, with negative years allowed. The timezone is always UTC. `toGMTString()` is an alias of this method.

Try it
------

Syntax
------


```js
toUTCString()
```

### Parameters

None.

### Return value

A string representing the given date using the UTC time zone (see description for the format). Returns `"Invalid Date"` if the date is invalid.

Description
-----------

The value returned by `toUTCString()` is a string in the form `Www, dd Mmm yyyy hh:mm:ss GMT`, where:

| Format String | Description |
| --- | --- |
| `Www` | Day of week, as three letters (e.g. `Sun`, `Mon`) |
| `dd` | Day of month, as two digits with leading zero if required |
| `Mmm` | Month, as three letters (e.g. `Jan`, `Feb`) |
| `yyyy` | Year, as four or more digits with leading zeroes if required |
| `hh` | Hour, as two digits with leading zero if required |
| `mm` | Minute, as two digits with leading zero if required |
| `ss` | Seconds, as two digits with leading zero if required |

### Aliasing

JavaScript's `Date` API was inspired by Java's `java.util.Date` library (while the latter had become de facto legacy since Java 1.1 in 1997). In particular, the Java `Date` class had a method called `toGMTString` — which was poorly named, because the Greenwich Mean Time is not equivalent to the Coordinated Universal Time, while JavaScript dates always operate by UTC time. For web compatibility reasons, `toGMTString` remains as an alias to `toUTCString`, and they refer to the exact same function object. This means:


```js
Date.prototype.toGMTString.name === "toUTCString";
```

Examples
--------

### Using toUTCString()


```js
const d = new Date(0);
console.log(d.toUTCString()); // 'Thu, 01 Jan 1970 00:00:00 GMT'
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.toutcstring |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Date.prototype.toLocaleString()`
* `Date.prototype.toString()`
* `Date.prototype.toISOString()`
Date.prototype.getDate()
========================

The **`getDate()`** method of `Date` instances returns the day of the month for this date according to local time.

Try it
------

Syntax
------


```js
getDate()
```

### Parameters

None.

### Return value

An integer, between 1 and 31, representing the day of the month for the given date according to local time. Returns `NaN` if the date is invalid.

Examples
--------

### Using getDate()

The `day` variable has value `25`, based on the value of the `Date` object `xmas95`.


```js
const xmas95 = new Date("1995-12-25T23:15:30");
const day = xmas95.getDate();

console.log(day); // 25
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.getdate |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Date.prototype.getUTCDate()`
* `Date.prototype.getUTCDay()`
* `Date.prototype.setDate()`
Date.prototype.getMonth()
=========================

The **`getMonth()`** method of `Date` instances returns the month for this date according to local time, as a zero-based value (where zero indicates the first month of the year).

Try it
------

Syntax
------


```js
getMonth()
```

### Parameters

None.

### Return value

An integer, between 0 and 11, representing the month for the given date according to local time: 0 for January, 1 for February, and so on. Returns `NaN` if the date is invalid.

Description
-----------

The return value of `getMonth()` is zero-based, which is useful for indexing into arrays of months, for example:


```js
const valentines = new Date("1995-02-14");
const month = valentines.getMonth();
const monthNames = ["January", "February", "March" /\* , … \*/];

console.log(monthNames[month]); // "February"
```


However, for the purpose of internationalization, you should prefer using `Intl.DateTimeFormat` with the `options` parameter instead.


```js
const options = { month: "long" };
console.log(new Intl.DateTimeFormat("en-US", options).format(valentines));
// "February"
console.log(new Intl.DateTimeFormat("de-DE", options).format(valentines));
// "Februar"
```

Examples
--------

### Using getMonth()

The `month` variable has value `11`, based on the value of the `Date` object `xmas95`.


```js
const xmas95 = new Date("1995-12-25T23:15:30");
const month = xmas95.getMonth();

console.log(month); // 11
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.getmonth |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Date.prototype.getUTCMonth()`
* `Date.prototype.setMonth()`
Date.prototype.getSeconds()
===========================

The **`getSeconds()`** method of `Date` instances returns the seconds for this date according to local time.

Try it
------

Syntax
------


```js
getSeconds()
```

### Parameters

None.

### Return value

An integer, between 0 and 59, representing the seconds for the given date according to local time. Returns `NaN` if the date is invalid.

Examples
--------

### Using getSeconds()

The `seconds` variable has value `30`, based on the value of the `Date` object `xmas95`.


```js
const xmas95 = new Date("1995-12-25T23:15:30");
const seconds = xmas95.getSeconds();

console.log(seconds); // 30
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.getseconds |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Date.prototype.getUTCSeconds()`
* `Date.prototype.setSeconds()`
Date.prototype.getUTCMinutes()
==============================

The **`getUTCMinutes()`** method of `Date` instances returns the minutes for this date according to universal time.

Try it
------

Syntax
------


```js
getUTCMinutes()
```

### Parameters

None.

### Return value

An integer, between 0 and 59, representing the minutes for the given date according to universal time. Returns `NaN` if the date is invalid.

Examples
--------

### Using getUTCMinutes()

The following example assigns the minutes portion of the current time to the variable `minutes`.


```js
const today = new Date();
const minutes = today.getUTCMinutes();
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.getutcminutes |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Date.prototype.getMinutes()`
* `Date.prototype.setUTCMinutes()`
Date.now()
==========

The **`Date.now()`** static method returns the number of milliseconds elapsed since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC.

Try it
------

Syntax
------


```js
Date.now()
```

### Parameters

None.

### Return value

A number representing the timestamp, in milliseconds, of the current time.

Description
-----------

### Reduced time precision

To offer protection against timing attacks and fingerprinting, the precision of `Date.now()` might get rounded depending on browser settings. In Firefox, the `privacy.reduceTimerPrecision` preference is enabled by default and defaults to 2ms. You can also enable `privacy.resistFingerprinting`, in which case the precision will be 100ms or the value of `privacy.resistFingerprinting.reduceTimerPrecision.microseconds`, whichever is larger.


```js
// reduced time precision (2ms) in Firefox 60
Date.now();
// 1519211809934
// 1519211810362
// 1519211811670
// …

// reduced time precision with `privacy.resistFingerprinting` enabled
Date.now();
// 1519129853500
// 1519129858900
// 1519129864400
// …
```

Examples
--------

### Measuring time elapsed

You can use `Date.now()` to get the current time in milliseconds, then subtract a previous time to find out how much time elapsed between the two calls.


```js
const start = Date.now();
doSomeLongRunningProcess();
console.log(`Time elapsed: ${Date.now() - start} ms`);
```


For more complex scenarios, you may want to use the performance API instead.

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.now |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Date.now` in `core-js`
* `Performance.now()`
* `console.time()`
* `console.timeEnd()`
Date.prototype.setUTCFullYear()
===============================

The **`setUTCFullYear()`** method of `Date` instances changes the year for this date according to universal time.

Try it
------

Syntax
------


```js
setUTCFullYear(yearValue)
setUTCFullYear(yearValue, monthValue)
setUTCFullYear(yearValue, monthValue, dateValue)
```

### Parameters

`yearValue`

An integer representing the year. For example, 1995.

`monthValue` Optional

An integer representing the month: 0 for January, 1 for February, and so on.

`dateValue` Optional

An integer between 1 and 31 representing the day of the month. If you specify `dateValue`, you must also specify `monthValue`.

### Return value

Changes the `Date` object in place, and returns its new timestamp. If a parameter is `NaN` (or other values that get coerced to `NaN`, such as `undefined`), the date is set to Invalid Date and `NaN` is returned.

Description
-----------

 If you do not specify the `monthValue` and
 `dateValue` parameters, the values returned from the
 `getUTCMonth()` and
 `getUTCDate()` methods are used.

 If a parameter you specify is outside of the expected range,
 `setUTCFullYear()` attempts to update the other parameters and the date
 information in the `Date` object accordingly. For example, if you specify 15
 for `monthValue`, the year is incremented by 1
 (`yearValue + 1`), and 3 is used for the month.

Examples
--------

### Using setUTCFullYear()


```js
const theBigDay = new Date();
theBigDay.setUTCFullYear(1997);
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.setutcfullyear |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Date.prototype.getUTCFullYear()`
* `Date.prototype.setFullYear()`
Date.prototype.setUTCHours()
============================

The **`setUTCHours()`** method of `Date` instances changes the hours, minutes, seconds, and/or milliseconds for this date according to universal time.

Try it
------

Syntax
------


```js
setUTCHours(hoursValue)
setUTCHours(hoursValue, minutesValue)
setUTCHours(hoursValue, minutesValue, secondsValue)
setUTCHours(hoursValue, minutesValue, secondsValue, msValue)
```

### Parameters

`hoursValue`

An integer between 0 and 23 representing the hours.

`minutesValue` Optional

An integer between 0 and 59 representing the minutes.

`secondsValue` Optional

An integer between 0 and 59 representing the seconds. If you specify `secondsValue`, you must also specify `minutesValue`.

`msValue` Optional

An integer between 0 and 999 representing the milliseconds. If you specify `msValue`, you must also specify `minutesValue` and `secondsValue`.

### Return value

Changes the `Date` object in place, and returns its new timestamp. If a parameter is `NaN` (or other values that get coerced to `NaN`, such as `undefined`), the date is set to Invalid Date and `NaN` is returned.

Description
-----------

 If you do not specify the `minutesValue`,
 `secondsValue`, and `msValue` parameters,
 the values returned from the `getUTCMinutes()`, `getUTCSeconds()`,
 and `getUTCMilliseconds()` methods
 are used.

 If a parameter you specify is outside of the expected range, `setUTCHours()`
 attempts to update the date information in the `Date` object accordingly.
 For example, if you use 100 for `secondsValue`, the minutes will
 be incremented by 1 (`minutesValue + 1`), and 40 will be used for seconds.

Examples
--------

### Using setUTCHours()


```js
const theBigDay = new Date();
theBigDay.setUTCHours(8);
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.setutchours |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Date.prototype.getUTCHours()`
* `Date.prototype.setHours()`
Date.prototype.setUTCMilliseconds()
===================================

The **`setUTCMilliseconds()`** method of `Date` instances changes the milliseconds for this date according to universal time.

Try it
------

Syntax
------


```js
setUTCMilliseconds(millisecondsValue)
```

### Parameters

`millisecondsValue`

An integer between 0 and 999 representing the milliseconds.

### Return value

Changes the `Date` object in place, and returns its new timestamp. If `millisecondsValue` is `NaN` (or other values that get coerced to `NaN`, such as `undefined`), the date is set to Invalid Date and `NaN` is returned.

Description
-----------

 If a parameter you specify is outside of the expected range,
 `setUTCMilliseconds()` attempts to update the date information in the
 `Date` object accordingly. For example, if you use 1100 for
 `millisecondsValue`, the seconds stored in the `Date`
 object will be incremented by 1, and 100 will be used for milliseconds.

Examples
--------

### Using setUTCMilliseconds()


```js
const theBigDay = new Date();
theBigDay.setUTCMilliseconds(500);
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-date.prototype.setutcmilliseconds |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Date.prototype.getUTCMilliseconds()`
* `Date.prototype.setMilliseconds()`