Home  >  Article  >  Web Front-end  >  Detailed explanation of the use of Date.UTC() method in JavaScript_Basic knowledge

Detailed explanation of the use of Date.UTC() method in JavaScript_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 15:55:281359browse

This method takes a date and returns the number of milliseconds since midnight universal time on January 1, 1970.
Grammar

Date.year,month,day,[hours,[minutes,[seconds,[ms]]])

Note: Data in brackets are optional

Here are the details of the parameters:

  • year: four digits representing the year
  • month: an integer between 0 and 11, indicating the month
  • day: an integer between 1 and 31, representing the date
  • hours: an integer between 0 and 23, indicating the hour
  • minutes: an integer between 0 and 59, representing minutes
  • seconds: an integer between 0 and 59, representing seconds
  • ms: an integer between 0 and 999, representing milliseconds

Return value:

Number of milliseconds since midnight on January 1, 1970
Example:

<html>
<head>
<title>JavaScript UTC Method</title>
</head>
<body>
<script type="text/javascript">
  var msecs = Date.UTC(2008,9,6);
  document.write( "Number of milliseconds from 1970: " + msecs ); 
</script>
</body>
</html>

This will produce the following results:

Number of milliseconds from 1970: 1223251200000 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn