Date.diff
Date.diff
功能
返回两个日期之间按指定单位换算后的差值。
语法
date_value.diff(other, unit)
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| other | Date/String/Number | 是 | 无 | 另一个日期。 |
| unit | String | 否 | millis | 差值单位。 |
返回值
| 类型 | 说明 |
|---|---|
| Int | 当前日期减去 other 后的差值。 |
代码示例
start = date('2026-01-01 00:00:00') end = start.add(2, 'days') result = end.diff(start, 'days') // 输出:2 print result
注意事项
- 支持单位:millis、seconds、minutes、hours、days、weeks。