Home » JavaScript

Get current UTC time in Hours24: Minutes: Seconds format in JavaScript

JavaScript getting the current UTC time in HH24:MM:SS format: Here, we are going to learn how to get the current UTC time in JavaScript in Hours24 : Minutes : Seconds format?
Submitted by IncludeHelp, on March 04, 2019

Getting current UTC time in JavaScript

To get the current UTC time in JavaScript, we need to use three library functions of Date class,

  1. Date getUTCHours() Method – It returns current UTC hours
  2. Date getUTCMinutes() Method – It returns current UTC minutes
  3. Date getUTCSeconds() Method – It returns current UTC seconds

Note: To call these functions, we need to create an object to the Date class using Date class constructor.

Examples:

    Date class constructor:
    var dt = new Date();

    Function calls:
    dt.getUTCHours();
    dt.getUTCMinues();
    dt.getUTCSeconds();
    
    Output:
    18
    22
    38

JavaScript code to get the current UTC time in Hours24: Minutes: Seconds format

<html>
<head><title>JavaScipt Example</title></head>

<body>
<script>
	var dt = new Date(); //Date constructor 
	var hh = dt.getUTCHours();
	var mm = dt.getUTCMinutes();
	var ss = dt.getUTCSeconds();
	//printing time
	document.write("Current UTC time is= " + hh + ":" + mm + ":" + ss + "<br>");
</script>
</body>
</html>

Output

Current UTC time is= 18:22:38





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.