arayts
Version:
让 TypeScript 开发如丝般顺滑。ArayTS 提供了一套高效、优雅的算法工具集,包含常用的数据结构与算法实现,帮助开发者轻松构建可靠的应用程序。
163 lines • 4.99 kB
TypeScript
export declare class TimeUtils {
private static getFormattedLocalDate;
static get(format?: string): string;
static range(verifiedDate: string, previousDate: string, laterDate?: string): boolean;
static days(previousDate: string, laterDate?: string): number;
static months(previousDate: string, laterDate?: string): number;
static years(previousDate: string, laterDate?: string): number;
static order(previousDate: string, laterDate?: string): boolean;
/**
* 获取当前时间戳(毫秒)
*/
static timestamp(): number;
/**
* 获取指定日期的时间戳(毫秒)
*/
static getTimestamp(date: string | Date): number;
/**
* 格式化时间为指定格式
* @param format 支持:YYYY-MM-DD HH:mm:ss
*/
static formatDate(date?: Date | string, format?: string): string;
/**
* 判断是否为同一天
*/
static isSameDay(date1: Date | string, date2: Date | string): boolean;
/**
* 获取指定日期是星期几
* @returns 0-6 (0表示星期日)
*/
static getWeekDay(date?: Date | string): number;
/**
* 获取相对时间描述
*/
static getRelativeTime(date: Date | string): string;
/**
* 添加时间
*/
static addTime(date: Date | string, num: number, unit: 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'): Date;
}
export declare class DateUtils {
private static readonly DEFAULT_FORMAT;
private static readonly TIME_FORMAT;
private static readonly FULL_FORMAT;
/**
* 格式化日期
*/
static format(date: Date | string | number, format?: string): string;
/**
* 解析日期字符串
*/
static parse(dateStr: string, format?: string): Date;
/**
* 日期比较
*/
static compare(date1: Date | string, date2: Date | string): number;
/**
* 日期加减
*/
static add(date: Date | string, amount: number, unit: 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'): Date;
/**
* 获取时间差
*/
static diff(date1: Date | string, date2: Date | string, unit: 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'): number;
/**
* 是否为有效日期
*/
static isValid(date: any): boolean;
/**
* 是否为闰年
*/
static isLeapYear(year: number): boolean;
/**
* 获取月份天数
*/
static getDaysInMonth(year: number, month: number): number;
/**
* 获取日期范围
*/
static getDateRange(start: Date | string, end: Date | string): Date[];
/**
* 获取月份范围内的所有月份
*/
static getMonthRange(startDate: Date | string, endDate: Date | string): Date[];
/**
* 按周对日期进行分组
*/
static groupByWeek(dates: (Date | string)[]): Date[][];
/**
* 判断两个日期是否在同一周
*/
static isSameWeek(date1: Date | string, date2: Date | string): boolean;
/**
* 获取指定年月的所有日期
*/
static getDatesInMonth(year: number, month: number): Date[];
/**
* 获取日期是当年的第几周
*/
static getWeekOfYear(date: Date | string): number;
/**
* 获取两个日期之间的季度列表
*/
static getQuarterRange(startDate: Date | string, endDate: Date | string): {
year: number;
quarter: number;
}[];
/**
* 获取指定日期的节假日信息(示例)
*/
static getHoliday(date: Date | string): string | null;
/**
* 格式化时间段
*/
static formatDuration(milliseconds: number): string;
/**
* 获取相对时间描述
*/
static getRelativeTime(date: Date | string): string;
private static padZero;
private static diffYears;
private static diffMonths;
/**
* 获取日期的开始时间(00:00:00)
*/
static startOfDay(date: Date | string): Date;
/**
* 获取日期的结束时间(23:59:59)
*/
static endOfDay(date: Date | string): Date;
/**
* 获取月份的第一天
*/
static startOfMonth(date: Date | string): Date;
/**
* 获取月份的最后一天
*/
static endOfMonth(date: Date | string): Date;
/**
* 获取日期是第几季度
*/
static getQuarter(date: Date | string): number;
/**
* 获取工作日信息(周末返回false)
*/
static isWorkday(date: Date | string): boolean;
/**
* 获取两个日期之间的工作日数量
*/
static getWorkdayCount(startDate: Date | string, endDate: Date | string): number;
/**
* 获取日期所在周的周一
*/
static startOfWeek(date: Date | string): Date;
/**
* 获取日期所在周的周日
*/
static endOfWeek(date: Date | string): Date;
/**
* 获取年龄
*/
static getAge(birthDate: Date | string): number;
}
//# sourceMappingURL=date.d.ts.map