閱讀807 返回首頁    go 阿裏雲 go 技術社區[雲棲]


關於new Date().getTime()的簡寫方式.

 Demo1: 運行
	 alert(  new Date().getTime() );
	 alert(  typeof (  new Date().getTime() ) );
		

Demo2: 運行
	 alert(  + new Date() );
	 alert(  typeof (   + new Date()  ) );
		

Demo3: 運行(發現它們相同)
	 alert( ( +new Date() )  + " ; " + ( new Date().getTime() )  );
		

	小結:
	(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!");
	}
		

最後更新:2017-04-02 06:51:55

  上一篇:go [usaco] 4.1.4 PROB Cryptcowgraphy
  下一篇:go 獲取android手機裏的所有應用,點擊並響應