手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表Tag:date

JS取当时间的一个很妖的方法

关于new Date().getTime()的简写方式.

原文来自cssrain,只取了其中的一小部分。http://www.cssrain.cn/demo/3/newDate.html

小结:
(1)getTime(new Date.getTime 方法)
返回指定的 Date 对象自 1970 年 1 月 1 日午夜(通用时间)以来的毫秒数。当比较两个或更多个 Date 对象时,使用此方法表示某一特定时刻。
返回值类型:Number -- 一个整数。

(2)
function now(){
return +new Date;
}
jQuery 源代码里就是使用的 +new Date ;

(3)
用来判断 google 浏览器:
if( !isNaN(Date.parse("1970.01.01")) ){
alert("This is Google Chrome!");
}else{
alert("This is NOT!");
}
结果:1和2的结果是一样的。但这个number是13位的number,和PHP中的时间戳并非同一个意义

Tags: time, jquery, gettime, date