mp:完成公众号统计的用户增减数据

This commit is contained in:
YunaiV
2023-01-07 22:35:30 +08:00
parent b9246d1543
commit 09e200c364
15 changed files with 591 additions and 12 deletions

View File

@ -32,3 +32,35 @@ export function beginOfDay(date) {
export function endOfDay(date) {
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999);
}
export function betweenDay(date1, date2) {
// 适配 string 字符串的日期
if (typeof date1 === 'string') {
date1 = new Date(date1);
}
if (typeof date2 === 'string') {
date2 = new Date(date2);
}
return Math.floor((date2.getTime() - date1.getTime()) / (24 * 3600 * 1000));
}
export function formatDate(date, fmt) {
const o = {
"M+": date.getMonth() + 1, //月份
"d+": date.getDate(), //日
"H+": date.getHours(), //小时
"m+": date.getMinutes(), //分
"s+": date.getSeconds(), //秒
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) { // 年份
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (const k in o) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
}
}
return fmt;
}