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

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

Try it
------

Syntax
------


```js
getUTCFullYear()
```

### Parameters

None.

### Return value

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

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

Unlike `getYear()`, the value returned by `getUTCFullYear()` 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 getUTCFullYear()

The following example assigns the four-digit value of the current year to the variable `year`.


```js
const today = new Date();
const year = today.getUTCFullYear();
```

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

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

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

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

See also
--------

* `Date.prototype.getFullYear()`
* `Date.prototype.setFullYear()`
Date.prototype.toJSON()
=======================

The **`toJSON()`** method of `Date` instances returns a string representing this date in the same ISO format as `toISOString()`.

Try it
------

Syntax
------


```js
toJSON()
```

### Parameters

None.

### Return value

A string representing the given date in the date time string format according to universal time, or `null` when the date is invalid. For valid dates, the return value is the same as that of `toISOString()`.

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

The `toJSON()` method is automatically called by `JSON.stringify()` when a `Date` object is stringified. This method is generally intended to, by default, usefully serialize `Date` objects during JSON serialization, which can then be deserialized using the `Date()` constructor as the reviver of `JSON.parse()`.

The method first attempts to convert its `this` value to a primitive by calling its `[@@toPrimitive]()` (with `"number"` as hint), `valueOf()`, and `toString()` methods, in that order. If the result is a non-finite number, `null` is returned. (This generally corresponds to an invalid date, whose `valueOf()` returns `NaN`.) Otherwise, if the converted primitive is not a number or is a finite number, the return value of `this.toISOString()` is returned.

Note that the method does not check whether the `this` value is a valid `Date` object. However, calling `Date.prototype.toJSON()` on non-`Date` objects fails unless the object's number primitive representation is `NaN`, or the object also has a `toISOString()` method.

Examples
--------

### Using toJSON()


```js
const jsonDate = new Date(0).toJSON(); // '1970-01-01T00:00:00.000Z'
const backToDate = new Date(jsonDate);

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

### Serialization round-tripping

When parsing JSON containing date strings, you can use the `Date()` constructor to revive them into the original date objects.


```js
const fileData = {
  author: "Maria",
  title: "Date.prototype.toJSON()",
  createdAt: new Date(2019, 3, 15),
  updatedAt: new Date(2020, 6, 26),
};
const response = JSON.stringify(fileData);

// Imagine transmission through network

const data = JSON.parse(response, (key, value) => {
  if (key === "createdAt" || key === "updatedAt") {
    return new Date(value);
  }
  return value;
});

console.log(data);
```


**Note:** The reviver of `JSON.parse()` must be specific to the payload shape you expect, because the serialization is *lossy*: it's not possible to distinguish between a string that represents a Date and a normal string.

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

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

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

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

See also
--------

* `Date.prototype.toLocaleDateString()`
* `Date.prototype.toTimeString()`
* `Date.prototype.toUTCString()`
Date.prototype.setMilliseconds()
================================

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

Try it
------

Syntax
------


```js
setMilliseconds(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 you specify a number outside the expected range, the date information in the `Date` object is updated accordingly. For example, if you specify 1005, the number of seconds is incremented by 1, and 5 is used for the milliseconds.

Examples
--------

### Using setMilliseconds()


```js
const theBigDay = new Date();
theBigDay.setMilliseconds(100);
```

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

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

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

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

See also
--------

* `Date.prototype.getMilliseconds()`
* `Date.prototype.setUTCMilliseconds()`
Date.prototype.setUTCDate()
===========================

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

Try it
------

Syntax
------


```js
setUTCDate(dateValue)
```

### Parameters

`dateValue`

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 `dateValue` 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 the `dateValue` is outside of the range of date values for the month, `setDate()` will update the `Date` object accordingly.

For example, if 0 is provided for `dateValue`, the date will be set to the last day of the previous month. If you use 40 for `dateValue`, and the month stored in the `Date` object is June, the day will be changed to 10 and the month will be incremented to July.

If a negative number is provided for `dateValue`, the date will be set counting backwards from the last day of the previous month. -1 would result in the date being set to 1 day before the last day of the previous month.

Examples
--------

### Using setUTCDate()


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

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

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

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

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

See also
--------

* `Date.prototype.getUTCDate()`
* `Date.prototype.setDate()`
Date.prototype.setTime()
========================

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

Try it
------

Syntax
------


```js
setTime(timeValue)
```

### Parameters

`timeValue`

An integer representing the new timestamp — the number of milliseconds since the midnight at the beginning of January 1, 1970, UTC.

### Return value

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

Examples
--------

### Using setTime()


```js
const theBigDay = new Date("1999-07-01");
const sameAsBigDay = new Date();
sameAsBigDay.setTime(theBigDay.getTime());
```

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

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

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

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

See also
--------

* `Date.prototype.getTime()`
* `Date.prototype.setUTCHours()`
Date.prototype.setMinutes()
===========================

The **`setMinutes()`** method of `Date` instances changes the minutes for this date according to local time.

Try it
------

Syntax
------


```js
setMinutes(minutesValue)
setMinutes(minutesValue, secondsValue)
setMinutes(minutesValue, secondsValue, msValue)
```

### Parameters

`minutesValue`

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 `secondsValue` and `msValue` parameters, the same values as what are returned by `getSeconds()` and `getMilliseconds()` are used.

If a parameter you specify is outside of the expected range, other parameters and the date information in the `Date` object are updated accordingly. For example, if you specify 100 for `secondsValue`, the minutes is incremented by 1 (`minutesValue + 1`), and 40 is used for seconds.

Examples
--------

### Using setMinutes()


```js
const theBigDay = new Date();
theBigDay.setMinutes(45);
```

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

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

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.prototype.getUTCHours()
============================

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

Try it
------

Syntax
------


```js
getUTCHours()
```

### Parameters

None.

### Return value

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

Examples
--------

### Using getUTCHours()

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


```js
const today = new Date();
const hours = today.getUTCHours();
```

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

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

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

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

See also
--------

* `Date.prototype.getHours()`
* `Date.prototype.setUTCHours()`
Date.prototype.getDay()
=======================

The **`getDay()`** method of `Date` instances returns the day of the week for this date according to local time, where 0 represents Sunday. For the day of the month, see `Date.prototype.getDate()`.

Try it
------

Syntax
------


```js
getDay()
```

### Parameters

None.

### Return value

An integer, between 0 and 6, representing the day of the week for the given date according to local time: 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on. Returns `NaN` if the date is invalid.

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

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


```js
const valentines = new Date("1995-02-14");
const day = valentines.getDay();
const dayNames = ["Sunday", "Monday", "Tuesday" /\* , … \*/];

console.log(dayNames[day]); // "Monday"
```


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


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

Examples
--------

### Using getDay()

The `weekday` variable has value `1`, based on the value of the `Date` object `xmas95`, because December 25, 1995 is a Monday.


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

console.log(weekday); // 1
```

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

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

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.getYear()
========================

**Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

The **`getYear()`** method of `Date` instances returns the year for this date according to local time. Because `getYear()` does not return full years ("year 2000 problem"), it is deprecated and has been replaced by the `getFullYear()` method.

Syntax
------


```js
getYear()
```

### Parameters

None.

### Return value

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

* For years greater than or equal to 2000, the value is 100 or greater. For example, if the year is 2026, `getYear()` returns 126.
* For years between and including 1900 and 1999, the value returned by `getYear()` is between 0 and 99. For example, if the year is 1976, `getYear()` returns 76.
* For years less than 1900, the value returned by `getYear()` is less than 0. For example, if the year is 1800, `getYear()` returns -100.

This method essentially returns the value of `getFullYear()` minus 1900. You should use `getFullYear()` instead, so that the year is specified in full.

Examples
--------

### Years between 1900 and 1999

The second statement assigns the value 95 to the variable `year`.


```js
const xmas = new Date("1995-12-25");
const year = xmas.getYear(); // returns 95
```

### Years above 1999

The second statement assigns the value 100 to the variable `year`.


```js
const xmas = new Date("2000-12-25");
const year = xmas.getYear(); // returns 100
```

### Years below 1900

The second statement assigns the value -100 to the variable `year`.


```js
const xmas = new Date("1800-12-25");
const year = xmas.getYear(); // returns -100
```

### Setting and getting a year between 1900 and 1999

The third statement assigns the value 95 to the variable `year`, representing the year 1995.


```js
const xmas = new Date("2015-12-25");
xmas.setYear(95);
const year = xmas.getYear(); // returns 95
```

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

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

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

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

See also
--------

* Polyfill of `Date.prototype.getYear` in `core-js`
* `Date.prototype.getFullYear()`
* `Date.prototype.getUTCFullYear()`
* `Date.prototype.setYear()`
Date.prototype.toTimeString()
=============================

The **`toTimeString()`** method of `Date` instances returns a string representing the time portion of this date interpreted in the local timezone.

Try it
------

Syntax
------


```js
toTimeString()
```

### Parameters

None.

### Return value

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

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

`Date` instances refer to a specific point in time. `toTimeString()` interprets the date in the local timezone and formats the *time* part in English. It always uses the format of `hh:mm:ss GMT±xxxx (TZ)`, where:

| Format String | Description |
| --- | --- |
| `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 |
| `±xxxx` | The local timezone's offset — two digits for hours and two digits for minutes (e.g. `-0500`, `+0800`) |
| `TZ` | The timezone's name (e.g. `PDT`, `PST`) |

For example: "04:42:04 GMT+0000 (Coordinated Universal Time)".

* If you only want to get the *date* part, use `toDateString()`.
* If you want to get both the date and time, use `toString()`.
* If you want to make the date interpreted as UTC instead of local timezone, use `toUTCString()`.
* If you want to format the date in a more user-friendly format (e.g. localization), use `toLocaleTimeString()`.
Examples
--------

### Using toTimeString()


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

console.log(d.toString()); // "Thu Jan 01 1970 00:00:00 GMT+0000 (Coordinated Universal Time)"
console.log(d.toTimeString()); // "00:00:00 GMT+0000 (Coordinated Universal Time)"
```

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

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

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

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

See also
--------

* `Date.prototype.toLocaleTimeString()`
* `Date.prototype.toDateString()`
* `Date.prototype.toString()`
Date.prototype.getUTCDate()
===========================

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

Try it
------

Syntax
------


```js
getUTCDate()
```

### Parameters

None.

### Return value

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

Examples
--------

### Using getUTCDate()

The following example assigns the day of month of the current date to the variable `dayOfMonth`.


```js
const today = new Date();
const dayOfMonth = today.getUTCDate();
```

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

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

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

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

See also
--------

* `Date.prototype.getUTCDate()`
* `Date.prototype.getDay()`
* `Date.prototype.setUTCDate()`
Date.prototype.toString()
=========================

The **`toString()`** method of `Date` instances returns a string representing this date interpreted in the local timezone.

Try it
------

Syntax
------


```js
toString()
```

### Parameters

None.

### Return value

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

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

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

The `Date` object overrides the `toString()` method of `Object`. `Date.prototype.toString()` returns a string representation of the Date as interpreted in the local timezone, containing both the date and the time — it joins the string representation specified in `toDateString()` and `toTimeString()` together, adding a space in between. For example: "Thu Jan 01 1970 00:00:00 GMT+0000 (Coordinated Universal Time)".

`Date.prototype.toString()` must be called on `Date` instances. If the `this` value does not inherit from `Date.prototype`, a `TypeError` is thrown.

* If you only want to get the *date* part, use `toDateString()`.
* If you only want to get the *time* part, use `toTimeString()`.
* If you want to make the date interpreted as UTC instead of local timezone, use `toUTCString()`.
* If you want to format the date in a more user-friendly format (e.g. localization), use `toLocaleString()`.
Examples
--------

### Using toString()


```js
const d = new Date(0);
console.log(d.toString()); // "Thu Jan 01 1970 00:00:00 GMT+0000 (Coordinated Universal Time)"
```

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

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

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

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

See also
--------

* `Object.prototype.toString()`
* `Date.prototype.toDateString()`
* `Date.prototype.toLocaleString()`
* `Date.prototype.toTimeString()`
Date.prototype.setHours()
=========================

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

Try it
------

Syntax
------


```js
setHours(hoursValue)
setHours(hoursValue, minutesValue)
setHours(hoursValue, minutesValue, secondsValue)
setHours(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 same values as what are returned by `getMinutes()`, `getSeconds()`, and `getMilliseconds()` are used.

If a parameter you specify is outside of the expected range, other parameters and the date information in the `Date` object are updated accordingly. For example, if you specify 100 for `secondsValue`, the minutes are incremented by 1 (`minutesValue + 1`), and 40 is used for seconds.

Examples
--------

### Using setHours()


```js
const theBigDay = new Date();
theBigDay.setHours(7);
```

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

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

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

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

See also
--------

* `Date.prototype.getHours()`
* `Date.prototype.setUTCHours()`