最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js new Date()實例測試

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

js new Date() 測試

var t = new Date().toString(); //t = "Thu Oct 31 2019 11:36:57 GMT+0800 (中國標準時間)"
 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 (中國標準時間)"
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()); 報錯
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());

擴展閱讀:

JS獲取當前時間戳的方法-JavaScript 獲取當前時間戳

JavaScript 獲取當前時間戳:

第一種方法:

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

結果:1280977330000

第二種方法:

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

結果:1280977330748

第三種方法:

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

結果:1280977330748

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

第二種和第三種是獲取了當前毫秒的時間戳。

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

可以用第二種或第三種方法計算時間差。

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

顯示的結果是:Mar 31 10:10:43 UTC+0800 2012 這種格式的時間

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

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

相關文章

最新評論

恩平市| 大埔区| 类乌齐县| 昌邑市| 揭东县| 安泽县| 绿春县| 崇义县| 且末县| 婺源县| 文山县| 双江| 习水县| 秦皇岛市| 广元市| 潞西市| 临猗县| 尚志市| 平南县| 墨竹工卡县| 江孜县| 都安| 平山县| 巴彦县| 新沂市| 福建省| 修文县| 平昌县| 重庆市| 南充市| 河源市| 鹤峰县| 什邡市| 内黄县| 溧阳市| 阳泉市| 堆龙德庆县| 库车县| 资中县| 庆云县| 浠水县|