w3resource

JavaScript UTC() Method: Date Object

Description

The UTC() method returns the number of milliseconds in a Date object since January 1, 1970, 00:00:00, universal time.

Version

Implemented in JavaScript 1.0

Syntax

UTC(year, month, day, hrs, min, sec, ms) 

Parameter

year :    A year after 1900.
month : An integer between 0 and 11 representing the month.
date :    An integer between 1 and 31 representing the day of the month.
hrs:       An integer between 0 and 23 representing the hours.

min:      An integer between 0 and 59 representing the minutes.

sec:      An integer between 0 and 59 representing the seconds.

ms:       An integer between 0 and 999 representing the milliseconds.

Example:

The following web document creates a date object using UTC() method and displays as a string.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>JavaScript date object - UTC() method example</title>
</head>
<body>
<h1 style="color: red">JavaScript date object : UTC() method</h1>
<hr />
<script type="text/javascript">
//This is done to make the following JavaScript code compatible to XHTML. <![CDATA[
utc_date =  new Date(Date.UTC(2009,7,19,21,4,9,10))
document.write(utc_date.toUTCString());
//]]>
</script>
</body>
</html>

View the example in the browser

Supported Browser

Internet Explorer 7 Firefox 3.6 Google Chrome 7 Safari 5.0.1 Opera 10
Yes Yes Yes Yes Yes

See also:

JavaScript Core objects, methods, properties.

Previous: JavaScript toUTCString() Method: Date Object
Next: JavaScript valueOf() Method: Date Object

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.