mirror of
https://github.com/imsyy/home.git
synced 2024-11-16 03:32:17 +08:00
fix: 修正建站日期统计算法
Signed-off-by: Libw·I <Libw-I@Libw.cc>
This commit is contained in:
parent
3d4607226c
commit
f333797484
|
@ -124,19 +124,21 @@ export const checkDays = () => {
|
||||||
// 建站日期统计
|
// 建站日期统计
|
||||||
export const siteDateStatistics = (startDate) => {
|
export const siteDateStatistics = (startDate) => {
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
const differenceInTime = currentDate.getTime() - startDate.getTime();
|
let years = currentDate.getFullYear() - startDate.getFullYear();
|
||||||
const differenceInDays = differenceInTime / (1000 * 3600 * 24);
|
let months = currentDate.getMonth() - startDate.getMonth();
|
||||||
const differenceInMonths = differenceInDays / 30;
|
let days = currentDate.getDate() - startDate.getDate();
|
||||||
const differenceInYears = differenceInMonths / 12;
|
|
||||||
if (differenceInYears >= 1) {
|
// 如果天数或月份为负数,则调整天数和月份
|
||||||
return `本站已经苟活了 ${Math.floor(differenceInYears)} 年 ${Math.floor(
|
if (days < 0) {
|
||||||
differenceInMonths % 12,
|
months--;
|
||||||
)} 月 ${Math.round(differenceInDays % 30)} 天`;
|
const lastMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, 0);
|
||||||
} else if (differenceInMonths >= 1) {
|
days += lastMonth.getDate();
|
||||||
return `本站已经苟活了 ${Math.floor(differenceInMonths)} 月 ${Math.round(
|
|
||||||
differenceInDays % 30,
|
|
||||||
)} 天`;
|
|
||||||
} else {
|
|
||||||
return `本站已经苟活了 ${Math.round(differenceInDays)} 天`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (months < 0) {
|
||||||
|
years--;
|
||||||
|
months += 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `本站已经苟活了 ${years} 年 ${months} 月 ${days} 天`;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user