智慧农业大数据平台
guoshilong
2022-10-17 0a3994b8a4e5d89639a0348f28754fc595d4d0e9
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// 日期转字符串格式
function DateToStr (date) {
    var year = date.getFullYear()// 年
    var month = date.getMonth()// 月
    var day = date.getDate()// 日
    var hours = date.getHours()// 时
    var min = date.getMinutes()// 分
    var second = date.getSeconds()// 秒
    return year + '-' +
        ((month + 1) > 9 ? (month + 1) : '0' + (month + 1)) + '-' +
        (day > 9 ? day : ('0' + day)) + ' ' +
        (hours > 9 ? hours : ('0' + hours)) + ':' +
        (min > 9 ? min : ('0' + min)) + ':' +
        (second > 9 ? second : ('0' + second))
}
function getToDay () {
    var date = new Date()
    var year = date.getFullYear()// 年
    var month = date.getMonth()// 月
    var day = date.getDate()// 日
    return year + '-' +
        ((month + 1) > 9 ? (month + 1) : '0' + (month + 1)) + '-' +
        (day > 9 ? day : ('0' + day)) + ' '
}
/**
 * 根据指定时间去返回天数
 * @param start 开始时间
 * @param end 结束时间
 * @returns {number} 天数
 */
function tmpTDiff (start, end) {
    const d1 = Date.parse(new Date(start))
    const d2 = Date.parse(new Date(end))
    // 时间戳相减 / 天数
    const day = parseInt((d2 - d1) / (1000 * 60 * 60 * 24))
    return day
}
 
/**
 * 获取多少月前的时间
 * @param num 多少月
 * @returns {string} yyyy-MM-dd 00:00:00
 */
function getSpecifyMonthDate (num) {
    const timeCount = new Date().getTime() - num * 30 * 24 * 60 * 60 * 1000
    const date = new Date(timeCount)
    return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} 00:00:00`
}
 
/**
 * 获取多少天前的时间
 * @param num 多少天
 * @returns {string} yyyy-MM-dd 00:00:00
 */
function getSpecifyDayDate (day) {
    const timeCount = new Date().getTime() - day * 24 * 60 * 60 * 1000
    const date = new Date(timeCount)
    var month = ""
    if (date.getMonth()+1<10){
        month = "0"+(date.getMonth()+1)
    }else {
        month = date.getMonth() + 1
    }
    return `${date.getFullYear()}-${month}-${date.getDate()} 00:00:00`
}
 
/**
 * 获取今天最后日期
 * @returns {string} yyyy-MM-dd 23:59:59
 */
function getDayLast () {
    const date = new Date()
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const strDate = date.getDate()
    return `${year}-${month}-${strDate} 23:59:59`
}
 
export default {
    DateToStr,
    getToDay,
    tmpTDiff,
    getSpecifyMonthDate,
    getSpecifyDayDate,
    getDayLast
}