当前位置: 首页 > 网络学院 > 客户端脚本教程 > JavaScript > JavaScript UTC()方法

JavaScript
JS 字符串
JS Date
JS数组,JS Array
JS Boolean
JS Math
JS HTML DOM
JS Browser
JS Cookies
JS 校验
JS Animation
JS Image Maps
JS Timing
JS 建立对象
JS 摘要
JS 实例
JS 对象实例
JS DOM 实例
JS数组对象参考
JS布尔对象参考
JS日期对象参考

JavaScript UTC()方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 298 ::
收藏到网摘: n/a

Definition and Usage
定义与用法

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号有多少毫秒。

Syntax
语法

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


Example
举例

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)
document.write(d)
</script>

The output of the code above will be:
输出结果为:

1123459200000


Example 2
举例 2

Now we will convert the output from the example above into years:
现在我们将上面的举例转换成输出年份差距:

<script type="text/javascript">
var minutes = 1000 * 60
var hours = minutes * 60
var days = hours * 24
var years = days * 365
var t = Date.UTC(2005,7,8)
var y = t/years
document.write("It's been: " + y + " years from 1970/01/01")
document.write(" to 2005/07/08!")
</script>

The output of the code above will be:
结果为:

It's been: 35.62465753424657 years from 1970/01/01 to 2005/07/08!


Try-It-Yourself Demos
尝试与演示

UTC()
Use UTC() to print the milliseconds from 1970/01/01 to a specified date (according to universal time).
使用UTC()根据国际时间输出的1970/01/01到指定日期所需要的毫秒数。

评论 (0) All

登陆 | 还没注册?