详情
This commit is contained in:
@ -349,63 +349,7 @@ class DateUtils {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前日期信息(增强版,包含年月信息)
|
||||
* @returns 包含各种格式的当前日期信息
|
||||
*/
|
||||
static getCurrentDateInfo() {
|
||||
const now = new Date();
|
||||
now.setHours(0, 0, 0, 0);
|
||||
|
||||
const monthRange = this.getMonthRange();
|
||||
const weekRange = this.getWeekRange();
|
||||
const yearMonth = this.getCurrentYearMonth();
|
||||
|
||||
return {
|
||||
current: {
|
||||
date: now,
|
||||
formatted: this.formatDate(now),
|
||||
dayOfWeek: this.getChineseDayOfWeek(now),
|
||||
day: now.getDate(),
|
||||
month: yearMonth.month,
|
||||
year: yearMonth.year,
|
||||
},
|
||||
month: {
|
||||
start: monthRange.start,
|
||||
end: monthRange.end,
|
||||
startFormatted: monthRange.startFormatted,
|
||||
endFormatted: monthRange.endFormatted,
|
||||
totalDays: this.getDaysInMonth(now.getFullYear(), now.getMonth() + 1),
|
||||
month: yearMonth.month,
|
||||
year: yearMonth.year,
|
||||
formatted: this.getFormattedYearMonth(),
|
||||
chinese: this.getChineseYearMonth(),
|
||||
},
|
||||
week: {
|
||||
start: weekRange.start,
|
||||
end: weekRange.end,
|
||||
startFormatted: weekRange.startFormatted,
|
||||
endFormatted: weekRange.endFormatted,
|
||||
weekNumber: this.getWeekNumber(now),
|
||||
},
|
||||
year: yearMonth.year,
|
||||
quarter: {
|
||||
number: this.getCurrentQuarter(),
|
||||
range: this.getCurrentQuarterRange(),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定日期所在的周数
|
||||
* @param date 日期对象
|
||||
* @returns 周数 (1-53)
|
||||
*/
|
||||
static getWeekNumber(date: Date): number {
|
||||
const firstDayOfYear = new Date(date.getFullYear(), 0, 1);
|
||||
const pastDaysOfYear = (date.getTime() - firstDayOfYear.getTime()) / 86400000;
|
||||
return Math.ceil((pastDaysOfYear + firstDayOfYear.getDay() + 1) / 7);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定年份的所有月份信息
|
||||
|
||||
Reference in New Issue
Block a user