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

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 parse()方法


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

Definition and Usage
定义与用法

The parse() method takes a date string and returns the number of milliseconds since midnight of January 1, 1970.
parse() 可获得一段日期字符串,是自1970年1月1号凌晨以来所用掉的毫秒数。

Syntax
语法

Date.parse(datestring)

Parameter
参数
Description
描述
datestring Required. A string representing a date
必选项。代表日期的字符串


Example
举例

In this example we will get how many milliseconds there are from 1970/01/01 to 2005/07/08:
在这个举例中我们将得到从1970/01/01 到2005/07/08 所用掉的毫秒数:

<script type="text/javascript">
var d = Date.parse("Jul 8, 2005")
document.write(d)
</script>

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

1120773600000


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.parse("Jul 8, 2005")
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.53949771689498 years from 1970/01/01 to 2005/07/08!


Try-It-Yourself Demos
尝试与演示

parse()
Use parse() to print the milliseconds from 1970/01/01 to a specified date.
使用parse()来输出1970/01/01到指定日期一共花去的毫秒数

评论 (0) All

登陆 | 还没注册?