JavaScript Date method: UTC()
[this page | pdf | back links]
The UTC() method (when applied to the JavaScript
Date object)
returns number of UTC milliseconds since 1 January 1970 00:00:00.
It
has the following syntax with the following parameters:
Date.UTC(year,month,day,hour,minute,second,millisecond)
Parameter
|
Required / Optional
|
Description
|
year
|
Required
|
Integer (with 4 digits
for years between 1000 and 9999).
|
month
|
Required
|
Integer representing
month of year. Typically, will be in range 0 – 11. However, -1 will result
last month of previous year, 12 will result in first month of next year etc.
|
day
|
Optional
|
Integer representing
day of month. Typically, will be in range 1 – 31. However, 0 will result in
last day of previous month, -1 the day before that etc., and e.g. 32 for a
30-day month will be second day of following month
|
hour
|
Optional
|
Integer representing
hour. Typically, will be in range 0 – 23. However, e.g. -1 will result in the
last hour of the previous day, 24 will result in the first hour of the next
day, etc.
|
minute
|
Optional
|
Integer representing
minutes. Typically, will be in range 0 – 59. However, e.g. -1 will result in
last minute of previous hour, 60 will result in first minute of next hour,
etc.
|
second
|
Optional
|
Integer representing
seconds. Typically, will be in range 0 – 59. However, e.g. 0 will result in
last second of previous minute, 60 will result in first second of next
minute, etc.
|
millisecond
|
Optional
|
Integer representing
milliseconds. Typically, will be in range 0 – 999. However, e.g. 0 will
result in last millisecond of previous second, 1000 will result in first
millisecond of next second, etc.
|
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>
<script>
var d = Date.now();
document.getElementById("Example").innerHTML =
'var x = new Date(Date.UTC(1970,12));';
document.getElementById("Result").innerHTML =
Date.UTC(1970,12).toString();
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodDateUTC() {
var d = new Date(Date.now()); return !!d.uTC;
} |
NAVIGATION LINKS
Contents | Prev | Next | JavaScript Dates