JavaScript Get UTC Hours, Minutes, Seconds, MilliSeconds

javascript get utc hours, minutes, seconds and milliseconds; Through this tutorial, i am going to show you how to get UTC time in hours, minutes, seconds and milliseconds in JavaScript with the help of examples.

javaScript Get UTC Time

There are four methods to get utc time in hours, minutes, seconds and milliseconds JavaScript; as shown below with examples:

  • getUTCHours()
  • getUTCMinutes()
  • getUTCSecond()
  • getUTCMilliSecond()

javaScript getUTCHours() Method

Javascript getUTCHours() method which is used to get the hour for the specified date and time, according to universal time. The getUTCHours method will return an integer value between 0 to 23.

Syntax of javaScript getUTCHours() Method

 Date.getUTCHours();

Example – javaScript getUTCHours() method

Let’s take an example for getting hour from current date javascript; as shown below:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript date.getUTCHours Method</title>
</head>
<body>
  <script type = "text/javascript">
     var currentDate = new Date();
     document.write("the javascript date.getUTCHours() : " + currentDate.getUTCHours() ); 
  </script>  
</body>
</html>

Result of the above code is:

JavaScript date.getUTCHours Method

JavaScript getUTCMinutes() Method

Javascript getUTCMinutes() method which is used to get the minute for the specified date and time, according to universal time. The getUTCMinutes method will return an integer value between 0 to 59.

Syntax of JavaScript getUTCMinutes() Method

date.getUTCMinutes();

Example of javaScript getUTCMinutes() method

Let’s take an example for getting minutes from current date javascript; as shown below:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript date.getUTCMinutes Method</title>
</head>
<body>
  <script type = "text/javascript">
     var currentDate = new Date();
     document.write("the javascript date.getUTCMinutes() : " + currentDate.getUTCMinutes() ); 
  </script>  
</body>
</html>

Result of the above code is:

JavaScript date.getUTCMinutes Method

javaScript getUTCSeconds() Method

Javascript getUTCSeconds() method, which is used to get the seconds for the specified date and time, according to universal time. The getUTCSeconds method will return an integer value between 0 to 59.

Syntax of javaScript getUTCSeconds() Method

date.getUTCSeconds();

Example of javaScript getUTCSeconds() method

Let’s take an example for getting current time in seconds javascript; as shown below:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript date.getUTCSeconds Method</title>
</head>
<body>
  <script type = "text/javascript">
     var currentDate = new Date();
     document.write("the javascript date.getUTCSeconds() : " + currentDate.getUTCSeconds() ); 
  </script>  
</body>
</html>

Result of the above code is:

JavaScript date.getUTCSeconds Method

JavaScript getUTCMilliseconds() Method

Javascript getUTCMilliseconds() method, which is used to get the milliseconds for the specified date and time, according to universal time. The getUTCMilliseconds method will return an integer value between 0 to 59.

Syntax of JavaScript getUTCMilliseconds() Method

 date.getUTCMilliseconds();

Example javaScript getUTCMilliseconds() method

Let’s take an example for getting the current time in milliseconds javascript; as shown below:

JavaScript date.getUTCMilliseconds Method

Result of the above code is:

JavaScript date.getUTCMilliseconds Method

Conclusion

In this javascript get utc time tutorial, you have learned how to get utc time in hours, minutes, seconds and milliseconds javascript with example.

Recommended MySQL Tutorials

Recommended:-JavaScript Arrays

Leave a Comment