智慧农业大数据平台
shuishen
2022-08-05 672916ea686709321ff3bd09c7a29cf9cfd7dee3
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
/**
 * 根据指定时间去返回天数
 * @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)
    return `${date.getFullYear()}-${date.getMonth() + 1}-${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() - 1
    return `${year}-${month}-${strDate} 23:59:59`
}
 
export default {
    tmpTDiff,
    getSpecifyMonthDate,
    getSpecifyDayDate,
    getDayLast
}