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

Date.getUTCMinutes() function in JavaScript


The Date object is a datatype 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 getUTCMinutes() function of the Date object returns the milliseconds in the given date according to the universal time.

Syntax

Its Syntax is as follows

dateObj.getUTCMinutes();

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

Output

34

Example

Incase if you haven’t mentioned the minutes of the hour (of the day) while creating the date object, this function returns 0 according to the universal time.

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var dataobj = new Date('September 26, 1989 GMT+11:00');
      document.write("Minutes: "+dataobj.getUTCMinutes());
   </script>
</body>
</html>

Output

Minutes: 0

Example

In the same way if you haven’t passed to the constructor of the date object this function returns the Current minutes according to the universal time.

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

Output

Minutes: 44