付延余
2022-09-07 513be798a677672644770e2b2f7025b6d4d20414
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const checkTime = function(i) {
    if (i < 10) {
        i = "0" + i;
    }
    return i;
}
 
 
 
export const showtime = function() {
    let nowdate = new Date();
    let year = nowdate.getFullYear(),
        month = checkTime(nowdate.getMonth() + 1),
        date = checkTime(nowdate.getDate());
    // day = nowdate.getDay(),
    // week = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
    // h = nowdate.getHours(),
    // m = nowdate.getMinutes(),
    // s = nowdate.getSeconds(),
    // h = checkTime(h),
    // m = checkTime(m),
    // s = checkTime(s);
    // return year + "年" + month + "月" + date + "日" + week[day] + " " + h + ":" + m + ":" + s;
    return year + '-' + month + '-' + date;
}
 
 
 
 
 
 
// 毫秒换算时间
export const timeConsuming = function(time) {
    let days = parseInt(time / (1000 * 60 * 60 * 24)),
        hours = parseInt((time % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)),
        minutes = parseInt((time % (1000 * 60 * 60)) / (1000 * 60)),
        seconds = (time % (1000 * 60)) / 1000;
    if (time >= 86400000) {
        return days + " 天 " + hours + " 小时 " + minutes + " 分钟 " + seconds + " 秒";
    } else if (time >= 3600000) {
        return hours + " 小时 " + minutes + " 分钟 " + seconds + " 秒";
    } else {
        return minutes + " 分钟 " + seconds + " 秒";
    }
}