tft每日頭條

 > 圖文

 > js怎麼弄簡單的時間循環

js怎麼弄簡單的時間循環

圖文 更新时间:2024-11-11 16:29:55

js怎麼弄簡單的時間循環?timeago(){var dddd = new Date("2022-03-25 18:05:00");,現在小編就來說說關于js怎麼弄簡單的時間循環?下面内容希望能幫助到你,我們來一起看看吧!

js怎麼弄簡單的時間循環(js實現幾年幾個月幾周幾天幾小時幾分鐘前以及剛剛的函數實現)1

js怎麼弄簡單的時間循環

timeago(){

var dddd = new Date("2022-03-25 18:05:00");

var dateTimeStamp = dddd.getTime()

var minute = 1000 * 60; //把分,時,天,周,半個月,一個月用毫秒表示

var hour = minute * 60;

var day = hour * 24;

var week = day * 7;

var month = day * 30;

var year = month * 12;

var now = new Date().getTime(); //獲取當前時間毫秒

var diffValue = now - dateTimeStamp;//時間差

var result = "";

if(diffValue < 0){

result = "" "未來";

}

var minC = diffValue/minute; //計算時間差的分,時,天,周,月

var hourC = diffValue/hour;

var dayC = diffValue/day;

var weekC = diffValue/week;

var monthC = diffValue/month;

var yearC = diffValue/year;

if(yearC >= 1){

result = " " parseInt(yearC) "年前"

}else if(monthC >= 1 && monthC < 12){

result = " " parseInt(monthC) "月前"

}else if(weekC >= 1 && weekC < 5 && dayC > 6 && monthC < 1){

result = " " parseInt(weekC) "周前"

}else if(dayC >= 1 && dayC <= 6){

result = " " parseInt(dayC) "天前"

}else if(hourC >= 1 && hourC <= 23){

result = " " parseInt(hourC) "小時前"

}else if(minC >= 1 && minC <= 59){

result =" " parseInt(minC) "分鐘前"

}else if(diffValue >= 0 && diffValue <= minute){

result = "剛剛"

}

console.log(result)

},

,

更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!

查看全部

相关圖文资讯推荐

热门圖文资讯推荐

网友关注

Copyright 2023-2024 - www.tftnews.com All Rights Reserved