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.
18 lines (17 loc) • 656 B
TypeScript
import { DateInput } from './types';
/**
* Calculates the difference in seconds between two dates.
* 计算两个日期之间的秒差
*
* @param date - The first date to compare.
* @param input - The second date to compare.
* @param asFloat - Whether to return the result as a float.
* @returns The difference in seconds between the two dates.
* @example
* ```ts
* diffInSeconds(new Date(), new Date()); // 0
* diffInSeconds(new Date(), new Date(Date.now() + 1000)); // 1
* diffInSeconds(new Date(), new Date(Date.now() - 1000)); // -1
* ```
*/
export default function diffInSeconds(date: Date, input: DateInput, asFloat?: boolean): number;