Home >>JavaScript Date Object Methods >JavaScript Date UTC() Method

JavaScript Date UTC() Method

JavaScript Date UTC() Method

JavaScript Date UTC() methodin JavaScript is used to return the number of milliseconds in a date object since midnight of January 1, 1970, according to universal time and the specified date and time.

Syntax:

Date.UTC(year, month, day, hours, minutes, seconds, millisec)

Parameter Values

Parameter Description
year It is Required. To specify the year after 1900 (four digit number representing the year), negative values are allowed
month It is Required. An integer between 0-11 representing the month other values are allowed:
  • 1 will provide you the last month of the previous year
  • 12 will provide you the first month of the next year
  • 13 will provide you the second month of the next year
day It is Optional. An integer (1 -31) represents the day of month. Other values are allowed:
  • 0 will provide you the last hour of the previous month
  • -1 will provide you the hour before the last hour of the previous month
  • If the month has 31 days then 32 will result the first day of the next month
  • If the month has 30 days then 32 will result the second day of the next month
hour It is Optional. An integer between 0-23 representing the hour. Its default value is Zero.

Other values are allowed:
  • -1 will show the last hour of the previous day
  • 24 will show the first hour of the next day
min It is Optional. An integer between 0-59 representing the minutes. Its default value is Zero.

Other values are allowed:
  • -1 will show the last minute of the previous hour
  • 60 will show the first minute of the next hour
sec It is Optional. An integer between 0-59 representing the seconds. Its default value is Zero.

Other values are allowed:
  • -1 will show the last second of the previous minute
  • 60 will show the first second of the next minute
millisec It is Optional. An integer between 0-999 representing the milliseconds. Its default value is Zero.

Other values are allowed:
  • -1 will show the last millisecond of the previous second
  • 1000 will show the first millisecond of the next second

Browser Support

Method Chrome Edge Firefox Safari Opera
UTC() Yes Yes Yes Yes Yes

Here is an example of JavaScript UTC() Method:

<html>
<body>
<button onclick="myUTC()">click me</button>
<p id="utc1"></p>
<script>
function myUTC() 
{
  var x = Date.UTC(2015, 08, 24);
  document.getElementById("utc1").innerHTML = x;
}
</script>
</body>
</html>
Output:

 

Example 2:

<html>
<body>		
<script> 
var test = new Date(Date.UTC(2010, 01, 28)); 
document.write( test); 
</script> 
</body>
</html>
Output: