Chuyển tới nội dung chính

DateTime():isSameOrBefore()

Kiểm tra xem đối tượng DateTime hiện tại có giống với hoặc nằm trước một đối tượng DateTime khác hay không.

Khai báo

isSameOrBefore(other: DateTime): boolean

Tham số

Tham sốKiểuMô tả
otherDateTimeĐối tượng DateTime khác để so sánh.

Trả về

  • Kiểu: boolean
  • true nếu DateTime hiện tại giống với hoặc nằm trước other DateTime, false nếu không.

Ví dụ

local date1 = DateTime(2024, 1, 5)
local date2 = DateTime(2024, 1, 10)
local date3 = DateTime(2024, 1, 5)

local result1 = date1:isSameOrBefore(date2) -- kết quả sẽ là true
toast(tostring(result1))

local result2 = date1:isSameOrBefore(date3) -- kết quả sẽ là true
toast(tostring(result2))

local result3 = date2:isSameOrBefore(date1) -- kết quả sẽ là false
toast(tostring(result3))