The Wayback Machine - https://web.archive.org/web/20240530200342/https://www.geeksforgeeks.org/javascript-date-getutcday-method/
Open In App

JavaScript Date getUTCDay() Method

Last Updated : 19 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The date.getUTCDay() method is used to fetch the day of a week according to universal time from a given Date object (ranging from 0 to 6, where 0 represents Sunday).

Syntax:  

DateObj.getUTCDay();

Parameter: This method does not accept any parameter. It is just used along with a Date Object from which we want to fetch the date of the month according to universal time.

Return Values: It returns the date of the month for the given date object according to universal time. The date of the month is an integer value ranging from 1 to 31.

Example 1: Below is an example of the Date getUTCDay() method. 

javascript




// If nothing is in parameter it takes
// the current date while creating Date object
let date = new Date();
 
// Date of the month from above date object
// is being extracted using getUTCDay().
let getUTC = date.getUTCDay();
 
// Printing day of the week
console.log(getUTC);


Output:  

1

Example 2: The date of the month should lie between 1 to 31 because none of the months have a date greater than 31 that is why it returns NaN i.e, not a number because the date for the month does not exist. 

javascript




// Here a date has been assigned according
// to universal time while creating a Date object
let dateobj =
    new Date('October 33, 1996 05:35:32 GMT-11:00');
 
// date of the month from above date object
// is being extracted using getUTCDay().
let B = dateobj.getUTCDay();
 
// Printing day of the week
console.log(B);


Output: 

NaN

Example 3: If the date of the month is not given then by default getUTCDay() function returns 1 according to universal time. It is an exceptional case. 

javascript




// Here a date has been assigned according to
// universal time while creating Date object
let dateobj =
    new Date('October 1996 05:35:32 GMT-11:00');
 
// date of the month from above date object is
// extracted using getUTCDay().
let B = dateobj.getUTCDay();
 
// Printing day of the week
console.log(B);


Output: 

2

We have a complete list of Javascript Javascript Date methods, to check those please go through the Javascript Date Object Complete Reference article.

Supported Browsers: The browsers supported by JavaScript Date getUTCDay() method are listed below: 

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 4 and above
  • Opera 4 and above
  • Safari 1 and above


Previous Article
Next Article

Similar Reads

How to validate if input date (end date) in input field must be after a given date (start date) using express-validator ?
In HTML forms, we often required validation of different types. Validate existing email, validate password length, validate confirm password, validate to allow only integer inputs, these are some examples of validation. In certain cases, we want the user to type a date that must come after some given date(Ex. 'end date' must be after 'start date')
5 min read
How to validate if input date (start date) in input field must be before a given date (end date) using express-validator ?
In HTML forms, we often required validation of different types. Validate existing email, validate password length, validate confirm password, validate to allow only integer inputs, these are some examples of validation. In certain cases, we want the user to type a date that must come before some given date (Ex: 'start date' must come before 'end da
5 min read
How to check the input date is equal to today's date or not using JavaScript ?
Given a date object and the task is to determine whether the given date is the same as today's date or not with the help of JavaScript. There are two well-famous approaches are discussed here. Approach 1: Get the input date from user (var inpDate) and the today's date by new Date(). Now, use .setHours() method on both dates by passing parameters of
3 min read
How to convert UTC date time into local date time using JavaScript ?
Given an UTC date and the task is to convert UTC date time into local date-time using JavaScript toLocaleString() function. Syntax: var theDate = new Date(Date.parse('DATE_IN_UTC')) theDate.toLocaleString() Example 1: This example converts UTC date time into local date time using JavaScript. C/C++ Code <body> <h1 style="color:green;
2 min read
Node.js date-and-time Date.isLeapYear() Method
The date-and-time.Date.isLeapYear() is a minimalist collection of functions for manipulating JS date and time module which is used to check if the given year is a leap year or not. Required Module: Install the module by npm or used it locally. By using npm: npm install date-and-time --save By using CDN link: <script src="/path/to/date-and-time.m
2 min read
Node.js date-and-time Date.transform() Method
The date-and-time.Date.transform() method is used to transform date and time from the existing string format to new string format. Required Module: Install the module by npm or used it locally. By using npm:npm install date-and-time --saveBy using CDN link:<script src="/path/to/date-and-time.min.js"></script> Syntax: const transform(dat
2 min read
Node.js date-and-time Date.locale() Method
The date-and-time.Date.locale() method is used to get or switch the locale from one into another language. Required Module: Install the module by npm or used it locally. By using npm: npm install date-and-time --save By using CDN link: <script src="/path/to/date-and-time.min.js"></script> Syntax: locale([code 1="locale" language="[,"][/
1 min read
Node.js date-and-time Date.isSameDay() Method
The date-and-time.Date.isSameDay() method is used to check if the given dates are the same or not. Required Module: Install the module by npm or used it locally. By using npm:npm install date-and-time --saveBy using CDN link:<script src="/path/to/date-and-time.min.js"></script> Syntax: isSameDay(date1, date2) Parameters: This method tak
2 min read
Node.js date-and-time Date.addSeconds() Method
The date-and-time.Date.addSeconds() method is used to add the extra Seconds to the existing date and time. Required Module: Install the module by npm or used it locally. By using npm:npm install date-and-time --saveBy using CDN link:<script src="/path/to/date-and-time.min.js"></script>Syntax: const addSeconds(dateObj, seconds)Parameters
2 min read
Node.js date-and-time Date.addMinutes() Method
The date-and-time.Date.addMinutes() method is used to add the extra Minutes to the existing date and time. Required Module: Install the module by npm or used it locally. By using npm:npm install date-and-time --saveBy using CDN link:<script src="/path/to/date-and-time.min.js"></script>Syntax: const addMinutes(dateObj, minutes)Parameters
2 min read