DateTime():diff()
現在の DateTime オブジェクトと別の DateTime オブジェクトとの差分を計算します。
シグネチャ
diff(other: DateTime): number
diff(other: DateTime, unit: string): number
パラメータ
| パラメータ | 型 | 説明 |
|---|---|---|
other | DateTime | 比較対象の別の DateTime オブジェクト。 |
unit (任意) | string | 差分の時間単位。指定しない場合、差分はミリ秒で返されます。対応する単位:milliseconds, seconds, minutes, hours, days |
戻り値
- 型:
number - ミリ秒単位の差分、または指定した場合はその単位での差分。
例
local date1 = DateTime(2024, 1, 10, 10, 0, 0)
local date2 = DateTime(2024, 1, 10, 9, 0, 0)
local diffMillis = date1:diff(date2) -- ミリ秒単位の差分
toast("Difference in milliseconds: " .. diffMillis)
local diffHours = date1:diff(date2, "hours") -- 時間単位の差分
toast("Difference in hours: " .. diffHours)
local diffDays = date1:diff(date2, "days") -- 日単位の差分
toast("Difference in days: " .. diffDays)