Date getUTCFullYear() method with example in JavaScript

JavaScript Date getUTCFullYear() method: Here, we are going to learn about the getUTCFullYear() method of Date class with Example in JavaScript.
Submitted by IncludeHelp, on March 08, 2019

JavaScript Date getUTCFullYear() method

getUTCFullYear() method is a Date's class method and it is used to get current year in the format of 4 digits according to the UTC (Universal time coordinated).

Syntax:

    var dt = new Date();
    dt.getUTCFullYear();

Examples:

    Input:
    var dt = new Date();
    dt.getUTCFullYear();
    
    Output:
    2019

JavaScript code to get the current UTC year using getUTCFullYear() method

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

<body>
<script>
	var dt = new Date(); //Date constructor 
	var year1 = dt.getUTCFullYear(); //UTC year 
	var year2 = dt.getUTCFullYear(); //local year 
	//printing year
	document.write("UTC year = " + year1 + "<br>");
	document.write("Local year = " + year2 + "<br>");
</script>
</body>
</html>

Output

UTC year = 2019
Local year = 2019

Reference: JavaScript getUTCFullYear() Method

JavaScript Date Object Methods »





Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.