当前位置: 首页 > 网络学院 > 客户端脚本教程 > JavaScript > JavaScript UTC()方法
The UTC() method takes a date and returns the number of milliseconds since midnight of January 1, 1970 according to universal time.
UTC()方法可以得到一个日期并根据国际时间返回相差1970年1月1号有多少毫秒。
Date.UTC(year,month,day,hours,minutes,seconds,ms) |
Parameter 参数 | Description 描述 |
---|---|
year | Required. A four digit number representing the year 必选。代表年份的四位数字 |
month | Required. An integer between 0 and 11 representing the month 必选。代表月份的整数,范围是0到11 |
day | Required. An integer between 1 and 31 representing the date 必选。代表日期的整数,范围是1到31 |
hours | Optional. An integer between 0 and 23 representing the hour 可选。代表小时的整数,范围是0到23 |
minutes | Optional. An integer between 0 and 59 representing the minutes 可选。代表分钟的整数,范围 0到59 |
seconds | Optional. An integer between 0 and 59 representing the seconds 可选。代表秒的整数,范围 0 到 59 |
ms | Optional. An integer between 0 and 999 representing the milliseconds 可选。代表毫秒的整数,范围 0到999 |
In this example we will get how many milliseconds there are from 1970/01/01 to 2005/07/08 according to universal time:
在举例中我们将根据国际时间得到1970/01/01到2005/07/08所用掉的毫秒数:
<script type="text/javascript"> var d = Date.UTC(2005,7,8) </script> |
The output of the code above will be:
输出结果为:
1123459200000 |
Now we will convert the output from the example above into years:
现在我们将上面的举例转换成输出年份差距:
<script type="text/javascript"> var minutes = 1000 * 60 </script> |
The output of the code above will be:
结果为:
It's been: 35.62465753424657 years from 1970/01/01 to 2005/07/08! |
UTC()
Use UTC() to print the milliseconds from 1970/01/01 to a specified date (according to universal time).
使用UTC()根据国际时间输出的1970/01/01到指定日期所需要的毫秒数。