Skip to content

Home > robinson > getDiff

getDiff() function

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

计算两个日期之间的差值。

Signature:

typescript
declare function getDiff(start: Tday, end: Tday, unitType: dayjs.OpUnitType, float?: boolean): number;
declare function getDiff(start: Tday, end: Tday, unitType: dayjs.OpUnitType, float?: boolean): number;

Parameters

ParameterTypeDescription
startTday开始日期,可以是 dayjs 对象、Date 对象或字符串。
endTday结束日期,可以是 dayjs 对象、Date 对象或字符串。
unitTypedayjs.OpUnitType时间单位类型。
floatboolean(Optional) 是否返回浮点数,默认为 false。

Returns:

number

{number} - 返回两个日期之间的差值。

Example

javascript
getDiff(dayjs('2024-03-02 08:00:00'), dayjs('2024-03-03 08:00:00'), 'd') // 1
getDiff(dayjs('2024-03-02 08:00:00'), dayjs('2024-04-03 08:00:00'), 'd') // 32
getDiff(dayjs('2024-03-02 08:00:00'), dayjs('2024-03-03 08:00:00'), 'd') // 1
getDiff(dayjs('2024-03-02 08:00:00'), dayjs('2024-04-03 08:00:00'), 'd') // 32

Released under the MIT License.