Home  >  Article  >  Web Front-end  >  详解JavaScript中Date.UTC()方法的使用_基础知识

详解JavaScript中Date.UTC()方法的使用_基础知识

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

 此方法需要一个日期,并返回自1970年1月1日按照通用时间午夜的毫秒数。
语法

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

注:括号内的数据是可选的

下面是参数的详细信息:

  •     year : 四位数字表示年
  •     month : 0和11之间的整数,表示月份
  •     day : 1到31之间的整数,表示日期
  •     hours : 0到23之间的整数,表示小时
  •     minutes : 0到59之间的整数,表示分钟
  •     seconds : 0到59之间的整数,表示秒
  •     ms :介于0和999之间的整数,表示毫秒

返回值:

自1970年1月1日午夜的毫秒数
例子:

<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>

这将产生以下结果:

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