function defineConst(name, value) {
Object.defineProperty(window, name, {
value,
writable: false,
configurable: false,
})
}
defineConst("a", 'aaa')
defineConst("PI", 3.14);
console.log(PI); // 3.14
PI = 2
function scopeConst(name, value) {
const scopeV = {}
if (scopeV.hasOwnProperty(name)) {
throw('errorrrr')
}
Object.defineProperty(scopeV, name, {
value,
writable: false,
configurable: false,
})
}
scopeConst()
const initTime = '2023/05/01 00:00:00'
const statisticsStartTime = '2023/05/01 00:00:00'
const statisticsEndTime = '2025/06/01 00:00:00'
const statisticsEndTimeDate = new Date(statisticsEndTime)
let startTime = statisticsStartTime
while (startTime < statisticsEndTime) {
let startTimeDate = new Date(startTime) // bj时间
// const bjDate = new Date(startTimeDate.getTime() + 8 * 60 * 60 * 1000); // UTC+8
const nextMonth = new Date(startTimeDate.getFullYear(), startTimeDate.getMonth() + 1, 1, 0, 0, 0);
console.log('next month: ', nextMonth.toString(), formatDate(nextMonth))
const endTime = formatDate(nextMonth)sta
// 再转回 UTC 前一日 16:00:00
// currentUTC = new Date(nextMonth.getTime() - 8 * 60 * 60 * 1000);
// console.log('currentUTC:', currentUTC.toISOString(), formatDate(currentUTC))
// const endTimestamp = startTimeDate.getTime() + 24 * 60 * 60 * 1000
// const endTimeDate = new Date(endTimestamp)
// const minEndDate = new Date(Math.min(endTimeDate, statisticsEndTimeDate))
// const endTime = formatDate(minEndDate)
// console.log(startTime)
// console.log(endTime)
// console.log("---------")
statisticsOneDay(startTime, endTime)
// startTime = endTime
}
function formatDate(date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`;
}
console