Date.getUTCDay() function in JavaScript


The Date object is a data type built into the JavaScript language. Date objects are created with the new Date( ) as shown below.

Once a Date object is created, a number of methods allow you to operate on it. Most methods simply allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time.

The getUTCDay() function of the Date object returns the day of the week of its current date according to the universal time. (0 represents Sunday and so on...)

Syntax

Its Syntax is as follows

dateObj.getUTCDay();

Example

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var dateObj = new Date('september 26, 89 12:4:25:96');
      document.write(dateObj.getUTCDay());
   </script>
</body>
</html>

Output

2

Example

If you do not mention the date of the month the getUTCDay() function considers it as the date is first and the day of the week is returned accordingly (based on universal time). For example we have mentioned the month as September 1989 and we haven’t mentioned the date so, by default it is considered that the date is 1 and since it is Thursday and since it is 5th day of the week this function returns 5.

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var dateObj = new Date('September, 1989 00:4:00');
      document.write(dateObj.getUTCDay());
   </script>
</body>
</html>

Output

4

Example

If you do not pass any value to the constructor while creating the date object then the getUTCDay() function returns the day of the week of the current date according to the universal time.

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var dateObj = new Date();
      document.write(dateObj.getUTCDay());
   </script>
</body>
</html>

Output

4

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 25-Jun-2020

16 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements