date-manip
Version:
A lightweight JavaScript date utility library that provides modularity, high performance, and additional features. It supports various date operations, including date addition and subtraction, formatting, comparison, etc.
17 lines (16 loc) • 653 B
TypeScript
/**
* Subtracts a specified number of years from a date.
* 从日期中减去指定数量的年份。
*
* @param date - The date to subtract years from. (要减去年份的日期。)
* @param years - The number of years to subtract. (要减去的年份数。)
* @returns A new date with the subtracted years. (减去年份后的新日期。)
* @example
* ```ts
* //Subtracting 2 years from a date (从日期中减去2)
* const date = new Date('2023-10-01T12:00:00Z');
* subYears(date, 2);
* // Returns: 2021-10-01T12:00:00.000Z (返回: 2021-10-01T12:00:00.000Z)
* ```
*/
export default function subYears(date: Date, years: number): Date;