亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

js new Date()實(shí)例測試

 更新時(shí)間:2019年10月31日 15:52:58   作者:enych  
在本篇文章中小編給各位整理的是關(guān)于js new Date()測試的相關(guān)實(shí)例代碼,有需要的朋友們參考學(xué)習(xí)下。

js new Date() 測試

var t = new Date().toString(); //t = "Thu Oct 31 2019 11:36:57 GMT+0800 (中國標(biāo)準(zhǔn)時(shí)間)"
 var t1 = new Date();
 var data_arry =[];
 var that = new Date();
 data_arry.push(that.constructor()); // Thu Oct 31 2019 11:50:26 GMT+0800 (中國標(biāo)準(zhǔn)時(shí)間)"
data_arry.push(that.getDate()); //31
data_arry.push(that.getDay()); // 4
data_arry.push(that.getFullYear()); //2019
data_arry.push(that.getHours()); // 11
data_arry.push(that.getMilliseconds()); // 401
data_arry.push(that.getMinutes()); // 50
data_arry.push(that.getMonth()); //9
data_arry.push(that.getSeconds()); //26
data_arry.push(that.getTime()); //1572493826401
data_arry.push(that.getTimezoneOffset()); //-480
data_arry.push(that.getUTCDate()); //31
data_arry.push(that.getUTCDay());
data_arry.push(that.getUTCFullYear());
data_arry.push(that.getUTCHours());
data_arry.push(that.getUTCMilliseconds());
data_arry.push(that.getUTCMinutes());
data_arry.push(that.getUTCMonth());
data_arry.push(that.getUTCSeconds());
data_arry.push(that.getYear());
data_arry.push(that.setDate());
data_arry.push(that.setFullYear());
data_arry.push(that.setHours());
data_arry.push(that.setMilliseconds());
data_arry.push(that.setMinutes());
data_arry.push(that.setMonth());
data_arry.push(that.setSeconds());
data_arry.push(that.setTime());
data_arry.push(that.setUTCDate());
data_arry.push(that.setUTCFullYear());
data_arry.push(that.setUTCHours());
data_arry.push(that.setUTCMilliseconds());
data_arry.push(that.setUTCMinutes());
data_arry.push(that.setUTCMonth());
data_arry.push(that.setUTCSeconds());
data_arry.push(that.setYear());
data_arry.push(that.toDateString());
data_arry.push(that.toGMTString());
//data_arry.push(that.toISOString()); 報(bào)錯(cuò)
data_arry.push(that.toJSON());
data_arry.push(that.toLocaleDateString());
data_arry.push(that.toLocaleString());
data_arry.push(that.toLocaleTimeString());
data_arry.push(that.toString());
data_arry.push(that.toTimeString());
data_arry.push(that.toUTCString());
data_arry.push(that.valueOf());

函數(shù)

 function get_nowtime() {
      var date = new Date();
      return (date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate());
    }
    console.log(get_nowtime());

擴(kuò)展閱讀:

JS獲取當(dāng)前時(shí)間戳的方法-JavaScript 獲取當(dāng)前時(shí)間戳

JavaScript 獲取當(dāng)前時(shí)間戳:

第一種方法:

var timestamp =Date.parse(new Date());

結(jié)果:1280977330000

第二種方法:

var timestamp =(new Date()).valueOf();

結(jié)果:1280977330748

第三種方法:

var timestamp=new Date().getTime();

結(jié)果:1280977330748

第一種:獲取的時(shí)間戳是把毫秒改成000顯示,

第二種和第三種是獲取了當(dāng)前毫秒的時(shí)間戳。

我和同事在用js實(shí)現(xiàn)一個(gè)顯示出分析數(shù)據(jù)所剩大概時(shí)間的過程中,時(shí)間總是變給0,結(jié)果很怪異,最后發(fā)現(xiàn)獲取時(shí)間的時(shí)候用的是Date.parse(newDate())獲取的時(shí)間戳把毫秒改成了000顯示,所以時(shí)間差計(jì)算的不準(zhǔn)確。

可以用第二種或第三種方法計(jì)算時(shí)間差。

js中單獨(dú)調(diào)用new Date(),例如document.write(new Date());

顯示的結(jié)果是:Mar 31 10:10:43 UTC+0800 2012 這種格式的時(shí)間

但是用new Date() 參與計(jì)算會(huì)自動(dòng)轉(zhuǎn)換為從1970.1.1開始的毫秒數(shù)

以上就是本次介紹的全部知識點(diǎn)以及擴(kuò)展內(nèi)容,感謝大家的學(xué)習(xí)和對腳本之家的支持。

  • JavaScript數(shù)值千分位格式化的兩種簡單實(shí)現(xiàn)方法

    JavaScript數(shù)值千分位格式化的兩種簡單實(shí)現(xiàn)方法

    下面小編就為大家?guī)硪黄狫avaScript數(shù)值千分位格式化的兩種簡單實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-08-08
  • JavaScript的內(nèi)存釋放問題詳解

    JavaScript的內(nèi)存釋放問題詳解

    這篇文章主要介紹了JavaScript的內(nèi)存釋放問題詳解的相關(guān)資料,需要的朋友可以參考下
    2015-01-01
  • 原生js實(shí)現(xiàn)each方法實(shí)例代碼詳解

    原生js實(shí)現(xiàn)each方法實(shí)例代碼詳解

    這篇文章主要介紹了原生js實(shí)現(xiàn)each方法,需要的朋友可以參考下
    2019-05-05
  • javascript+HTML5的canvas實(shí)現(xiàn)七夕情人節(jié)3D玫瑰花效果代碼

    javascript+HTML5的canvas實(shí)現(xiàn)七夕情人節(jié)3D玫瑰花效果代碼

    這篇文章主要介紹了javascript+HTML5的canvas實(shí)現(xiàn)七夕情人節(jié)3D玫瑰花效果代碼,使用了html5的canvas技術(shù),可呈現(xiàn)出帶有3D效果的玫瑰花漸顯效果,非常逼真自然,需要的朋友可以參考下
    2015-08-08
  • JavaScript實(shí)現(xiàn)獲取本機(jī)IP地址

    JavaScript實(shí)現(xiàn)獲取本機(jī)IP地址

    這篇文章主要介紹了JavaScript實(shí)現(xiàn)獲取本機(jī)IP地址方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • js實(shí)現(xiàn)文字滾動(dòng)的效果

    js實(shí)現(xiàn)文字滾動(dòng)的效果

    這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)文字滾動(dòng)的效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • uni-app?中清除定時(shí)器實(shí)現(xiàn)方法詳解

    uni-app?中清除定時(shí)器實(shí)現(xiàn)方法詳解

    這篇文章主要為大家介紹了uni-app?中清除定時(shí)器實(shí)現(xiàn)方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • js文字滾動(dòng)停頓效果代碼

    js文字滾動(dòng)停頓效果代碼

    javascript文字滾動(dòng)停頓效果的實(shí)現(xiàn)代碼
    2008-06-06
  • 最新評論