智慧农业大数据平台
xiebin
2022-11-16 3dc278f10a4c3e3db7ce3a445bed710bdc88916e
src/utils/dateUtils.js
@@ -1,3 +1,27 @@
// 日期转字符串格式
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 开始时间
@@ -24,14 +48,20 @@
}
/**
 * 获取多少月前的时间
 * @param num 多少月
 * 获取多少天前的时间
 * @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`
    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`
}
/**
@@ -42,11 +72,13 @@
    const date = new Date()
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const strDate = date.getDate() - 1
    const strDate = date.getDate()
    return `${year}-${month}-${strDate} 23:59:59`
}
export default {
    DateToStr,
    getToDay,
    tmpTDiff,
    getSpecifyMonthDate,
    getSpecifyDayDate,