'保安项目提交'
This commit is contained in:
65
src/utils/time.js
Normal file
65
src/utils/time.js
Normal file
@ -0,0 +1,65 @@
|
||||
// 日历数据时间段处理
|
||||
export function handleTime(start, end) {
|
||||
//补0
|
||||
function zeeo(num) {
|
||||
let data = num;
|
||||
if (num * 1 < 10) {
|
||||
data = "0" + num;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
let arr = [];
|
||||
let kssj = new Date(start).getTime();
|
||||
let jssj = new Date(end).getTime();
|
||||
let dayTimes = 24 * 60 * 60 * 1000;
|
||||
//天数
|
||||
let n = Math.floor((jssj - kssj) / dayTimes);
|
||||
for (var i = 0; i <= n; i++) {
|
||||
let mytime = kssj + i * dayTimes;
|
||||
arr.push({
|
||||
start:
|
||||
new Date(mytime).getFullYear() +
|
||||
"-" +
|
||||
zeeo(new Date(mytime).getMonth() + 1) +
|
||||
"-" +
|
||||
zeeo(new Date(mytime).getDate()),
|
||||
end:
|
||||
new Date(mytime).getFullYear() +
|
||||
"-" +
|
||||
zeeo(new Date(mytime).getMonth() + 1) +
|
||||
"-" +
|
||||
zeeo(new Date(mytime).getDate())
|
||||
});
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
export function timeValidate(date, type) {
|
||||
const time = date ? new Date(date) : new Date();
|
||||
const yyyy = time.getFullYear();
|
||||
const MM = (time.getMonth() + 1).toString().padStart(2, "0");
|
||||
const dd = time.getDate().toString().padStart(2, "0");
|
||||
const hh = time.getHours().toString().padStart(2, "0");
|
||||
const mm = time.getMinutes().toString().padStart(2, "0");
|
||||
const ss = time.getSeconds().toString().padStart(2, "0");
|
||||
if (type == "ymd") {
|
||||
return `${yyyy}-${MM}-${dd}`;
|
||||
}
|
||||
return `${yyyy}-${MM}-${dd} ${hh}:${mm}:${ss}`;
|
||||
}
|
||||
|
||||
//获取n天前或n天后的日期
|
||||
export function getTime(n) {
|
||||
var currentDate = new Date();
|
||||
var preDate = new Date(currentDate.getTime() + n * 24 * 3600 * 1000);
|
||||
let year = preDate.getFullYear();
|
||||
let mon = preDate.getMonth() + 1;
|
||||
let day = preDate.getDate();
|
||||
let s =
|
||||
year +
|
||||
"-" +
|
||||
(mon < 10 ? "0" + mon : mon) +
|
||||
"-" +
|
||||
(day < 10 ? "0" + day : day);
|
||||
return s;
|
||||
}
|
||||
Reference in New Issue
Block a user