跳到主要内容

DateTime():endOf()

DateTime 对象设置为指定时间单位的结束时刻(例如当天结束、当月结束)。

签名

endOf(unit: string): DateTime

参数

参数类型描述
unitString要设置结束时刻的时间单位。支持的单位包括:yearmonthweekdayhourminutesecond

返回值

  • 类型:DateTime
  • 当前的 DateTime 实例,可用于方法链式调用。

示例

local now = DateTime()
-- 设置为当天结束
now:endOf("day")
toast("End of day: " .. now:format("yyyy-MM-dd HH:mm:ss.SSS"))

-- 设置为当月结束
now = DateTime() -- 重置
now:endOf("month")
toast("End of month: " .. now:format("yyyy-MM-dd HH:mm:ss.SSS"))

-- 设置为当年结束
now = DateTime() -- 重置
now:endOf("year")
toast("End of year: " .. now:format("yyyy-MM-dd HH:mm:ss.SSS"))