小程序如何獲取系統(tǒng)時(shí)間、時(shí)間戳?xí)r間以及時(shí)間戳加減-創(chuàng)新互聯(lián)

這篇文章將為大家詳細(xì)講解有關(guān)小程序如何獲取系統(tǒng)時(shí)間、時(shí)間戳?xí)r間以及時(shí)間戳加減,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

創(chuàng)新互聯(lián)公司主營(yíng)井陘網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,app軟件開發(fā),井陘h5成都微信小程序搭建,井陘網(wǎng)站營(yíng)銷推廣歡迎井陘等地區(qū)企業(yè)咨詢
//獲取當(dāng)前時(shí)間戳
    var timestamp = Date.parse(new Date());
    timestamp = timestamp / 1000;
    console.log("當(dāng)前時(shí)間戳為:" + timestamp);
 
//獲取當(dāng)前時(shí)間
    var n = timestamp * 1000;
    var date = new Date(n);
    //年
    var Y = date.getFullYear();
    //月
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
    //日
    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    //時(shí)
    var h = date.getHours();
    //分
    var m = date.getMinutes();
    //秒
    var s = date.getSeconds();
  
    console.log("當(dāng)前時(shí)間:" +Y+M+D+h+":"+m+":"+s);
    
//轉(zhuǎn)換為時(shí)間格式字符串
    console.log(date.toDateString());
 
    console.log(date.toGMTString());
 
    console.log(date.toISOString());
  
    console.log(date.toJSON());
    
    console.log(date.toLocaleDateString());
 
    console.log(date.toLocaleString());
  
    console.log(date.toLocaleTimeString());
   
    console.log(date.toString());
   
    console.log(date.toTimeString());
   
    console.log(date.toUTCString());
//時(shí)間、時(shí)間戳加減 以加一天舉例,聰明的你肯定觸類旁通
    //加一天的時(shí)間戳:
    var tomorrow_timetamp = timestamp + 24 * 60 * 60;
    //加一天的時(shí)間:
    var n_to = tomorrow_timetamp * 1000;
    var tomorrow_date = new Date(n_to);
    //加一天后的年份
    var Y_tomorrow = tomorrow_date.getFullYear();
    //加一天后的月份
    var M_tomorrow = (tomorrow_date.getMonth() + 1 < 10 ? '0' + (tomorrow_date.getMonth() + 1) : tomorrow_date.getMonth() + 1);
    //加一天后的日期
    var D_tomorrow = tomorrow_date.getDate() < 10 ? '0' + tomorrow_date.getDate() : tomorrow_date.getDate();
    //加一天后的時(shí)刻
    var h_tomorrow = tomorrow_date.getHours();
    //加一天后的分鐘
    var m_tomorrow = tomorrow_date.getMinutes();
    //加一天后的秒數(shù)
    var s_tomorrow = tomorrow_date.getSeconds();

關(guān)于“小程序如何獲取系統(tǒng)時(shí)間、時(shí)間戳?xí)r間以及時(shí)間戳加減”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

本文標(biāo)題:小程序如何獲取系統(tǒng)時(shí)間、時(shí)間戳?xí)r間以及時(shí)間戳加減-創(chuàng)新互聯(lián)
鏈接URL:http://muchs.cn/article0/cddcoo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、網(wǎng)站排名微信小程序、服務(wù)器托管外貿(mào)網(wǎng)站建設(shè)、小程序開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管