最新国产好看的视频,伊人天堂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());

函數

 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實現一個顯示出分析數據所剩大概時間的過程中,時間總是變給0,結果很怪異,最后發(fā)現獲取時間的時候用的是Date.parse(newDate())獲取的時間戳把毫秒改成了000顯示,所以時間差計算的不準確。

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

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

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

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

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

相關文章

  • 用js實現計算加載頁面所用的時間

    用js實現計算加載頁面所用的時間

    用js實現計算加載頁面所用的時間的代碼,需要的朋友可以參考下。
    2010-04-04
  • 不使用JavaScript實現菜單的打開和關閉效果demo

    不使用JavaScript實現菜單的打開和關閉效果demo

    本文通過實例代碼給大家分享在不使用JavaScript實現菜單的打開和關閉效果,非常不錯,具有參考借鑒價值,需要的朋友參考下吧
    2018-05-05
  • 用JS寫了一個30分鐘倒計時器的實現示例

    用JS寫了一個30分鐘倒計時器的實現示例

    本文主要介紹了用JS寫了一個30分鐘倒計時器的實現示例,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • JavaScript實現簡單獲取當前網頁網址的方法

    JavaScript實現簡單獲取當前網頁網址的方法

    這篇文章主要介紹了JavaScript實現簡單獲取當前網頁網址的方法,通過location對象的href方法來獲取網址,非常簡單實用,需要的朋友可以參考下
    2015-11-11
  • JavaScript調試工具匯總

    JavaScript調試工具匯總

    這篇文章主要介紹了7款基于桌面和WEB的JavaScript調試工具,更有效地處理動態(tài)類型使應用程序更符合編碼標準,不管你是新學習javascript的菜鳥還是業(yè)界大神,都非常的有用。
    2014-12-12
  • iframe高度自適應及隱藏滾動條的實例詳解

    iframe高度自適應及隱藏滾動條的實例詳解

    這篇文章主要介紹了iframe高度自適應及隱藏滾動條的實例詳解的相關資料,希望通過本文能幫助到大家,需要的朋友可以參考下
    2017-09-09
  • layerui代碼控制tab選項卡,添加,關閉的實例

    layerui代碼控制tab選項卡,添加,關閉的實例

    今天小編就為大家分享一篇layerui代碼控制tab選項卡,添加,關閉的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-09-09
  • js中數組結合字符串實現查找(屏蔽廣告判斷url等)

    js中數組結合字符串實現查找(屏蔽廣告判斷url等)

    這篇文章主要介紹了js中數組結合字符串實現查找(屏蔽廣告判斷url等),需要的朋友可以參考下
    2016-03-03
  • 超詳細JavaScript深淺拷貝的實現教程

    超詳細JavaScript深淺拷貝的實現教程

    淺拷貝是指,一個新的對象對原始對象的屬性值進行精確地拷貝;深拷貝是指,對于簡單數據類型直接拷貝他的值,對于引用數據類型,在堆內存中開辟一塊內存用于存放復制的對象,并把原有的對象類型數據拷貝過來。本文將實現JavaScript深淺拷貝,需要的可以參考一下
    2022-09-09
  • layer彈出子iframe層父子頁面?zhèn)髦档膶崿F方法

    layer彈出子iframe層父子頁面?zhèn)髦档膶崿F方法

    這篇文章主要介紹了layer彈出子iframe層父子頁面?zhèn)髦档膶崿F方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2018-11-11

最新評論

长顺县| 武川县| 邳州市| 奉化市| 会宁县| 灯塔市| 镶黄旗| 辽宁省| 仙游县| 阿克苏市| 井冈山市| 喜德县| 天津市| 昔阳县| 固安县| 长丰县| 山阴县| 通渭县| 宣恩县| 辽阳市| 甘德县| 台中市| 札达县| 宜章县| 滦南县| 留坝县| 左权县| 浏阳市| 土默特左旗| 临清市| 屯留县| 古蔺县| 苏尼特右旗| 巴里| 新丰县| 九江县| 浑源县| 宜章县| 那曲县| 宁乡县| 商南县|