Home >>JavaScript Date Object Methods >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 | 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:
|
day | It is Optional. An integer (1 -31) represents the day of month. Other values are allowed:
|
hour | It is Optional. An integer between 0-23 representing the hour. Its default value is Zero. Other values are allowed:
|
min | It is Optional. An integer between 0-59 representing the minutes. Its default value is Zero. Other values are allowed:
|
sec | It is Optional. An integer between 0-59 representing the seconds. Its default value is Zero. Other values are allowed:
|
millisec | It is Optional. An integer between 0-999 representing the milliseconds. Its default value is Zero. Other values are allowed:
|
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>
Example 2:
<html> <body> <script> var test = new Date(Date.UTC(2010, 01, 28)); document.write( test); </script> </body> </html>