JavaScript Date getUTCDate() Method

The getUTCDate() method in JavaScript is a part of the Date object and is used to get the day of the month (1-31) for a given date object, in the UTC time zone. This can be useful for getting the day of the month in a specific time zone, or for working with dates in a consistent time zone.

Here’s an example of how to use getUTCDate() to get the current day of the month in UTC time:

let date = new Date();
let day = date.getUTCDate();
console.log(day);  // Outputs the current day of the month in UTC time

You can also pass a date object as an argument to getUTCDate() to get the day of the month for a specific date in UTC time:

let date = new Date(2022, 0, 1, 11, 30, 0);  // January 1, 2022 at 11:30:00 (local time)
let day = date.getUTCDate();
console.log(day);  // Outputs 1

Note that the getUTCDate() method returns the day of the month as a number, with 1 representing the first day of the month, 2 representing the second day, and so on.

In addition to getting the day of the month, you can also use the setUTCDate() method to set the day of the month for a date object in UTC time. Here’s an example of how to use it:

let date = new Date();
date.setUTCDate(15);  // Set the day of the month to 15
console.log(date);  // Outputs the current date and time with the day of the month set to 15 in UTC time

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: