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

JavaScript
JS数学对象参考
JS字符串对象参考
JS函数参考
JS事件参考
Javascript 常用正则表达式
FF和IE下的js兼容性问题
jQuery 简单介绍
jQuery / 核心 / $(expression, [context] ) 函数
jQuery / 核心 / $(html) 函数
如何使用JS来判断浏览器类型(ie、firefox,等等)
Javascript在IE和FireFox中的不同表现
3个js字符编码函数区别
javascript 中的 XMLDOM 对象

JavaScript parse()方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 352 ::
收藏到网摘: 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

登陆 | 还没注册?