You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

function _getDate(date) {
var year = date.getFullYear(),
month = date.getMonth() + 1,
day = date.getDate();
return `${year}-${fillZero(month)}-${fillZero(day)}`
}
function fillZero(val) {
return (val < 10 ? '0' : '') + val;
}
export default {
getDate() {
var date = new Date();
return _getDate(date);
},
getDateTime() {
var date = new Date();
var hour = fillZero(date.getHours()),
minute = fillZero(date.getMinutes()),
second = fillZero(date.getSeconds());
return `${ _getDate(date)} ${hour}:${minute}:${second}`;
},
//日期+多少天
//日期-10天this.base.date('2023-04-02',-10)
//当天日期-10天this.base.date(this.base.getDate(),-10)
addDay(date, days) {
if (!days) {
return date;
}
date = new Date(new Date(date).setDate(new Date(date).getDate() + days));
var year = date.getFullYear();
var month = date.getMonth() + 1;
if (month < 10) {
month = "0" + month;
}
var day = date.getDate();
if (day < 10) {
day = "0" + day;
}
return year + "-" + month + "-" + day;
},
//日期+多少月,同上
addMonth(date, m) {
date = new Date(
new Date(date).setMonth(
new Date(date).getMonth() + (m === undefined ? 1 : m)
)
);
var year = date.getFullYear();
var month = date.getMonth() + 1;
if (month < 10) {
month = "0" + month;
}
var day = date.getDate();
if (day < 10) {
day = "0" + day;
}
return year + "-" + month + "-" + day;
},
isEmpty(value, checkArr) {
if (checkArr) {
if (Array.isArray(value)) {
if (!value.length) {
return true;
}
}
}
return value === '' || value === ' ' || value === undefined || value === null || value === 'null'
}
}