Computer >> Computer tutorials >  >> Programming >> Javascript

Date.getUTCDate() 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 getUTCDate() function of the Date object returns the day of the month of its current date according to the universal time.

Syntax

Its Syntax is as follows

dateObj.getUTCDate();

Example

<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.getUTCDate());
   </script>
</body>
</html>

Output

26

Example

If you do not mention the date of the month by default 1 will be returned by this function according to the universal time.

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

Output

31

Example

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

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

Output

25