.getUTCMonth()

Published Jun 15, 2023
Contribute to Docs

Get methods are used to retrieve date components based on the user’s local timezone settings. The .getUTCMonth() method returns the month of the date passed, similar to .getMonth(). However, .getUTCMonth() calculates the time based on the UTC (Coordinated Universal Time) standard.

Syntax

const today = new Date();
const month = today.getUTCMonth();

Example above assigns the month portion of the current Date to the variable month.

Example

const date1 = new Date('December 31, 1975, 23:15:30 GMT+11:00');
const date2 = new Date('December 31, 1975, 23:15:30 GMT-11:00');
console.log(date1.getUTCMonth());
console.log(date2.getUTCMonth());

This results in the following output:

11
0

All contributors

Looking to contribute?

Learn JavaScript on Codecademy