// 日期转字符串格式
|
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
|
}
|