Saltar al contenido principal

DateTime():startOf()

Establece el objeto DateTime al inicio de una unidad de tiempo especificada (p. ej., inicio del día, inicio del mes).

Firma

startOf(unit: string): DateTime

Parámetros

ParámetroTipoDescripción
unitstringLa unidad de tiempo cuyo inicio se desea establecer. Las unidades admitidas incluyen:year, month, week, day, hour, minute, second

Devuelve

  • Tipo: DateTime
  • La instancia actual de DateTime, lo que permite el encadenamiento de métodos.

Ejemplos

local now = DateTime()
-- Set to the start of the current day
now:startOf("day")
toast("Start of day: " .. now:format("yyyy-MM-dd HH:mm:ss.SSS"))

-- Set to the start of the current month
now = DateTime() -- Reset
now:startOf("month")
toast("Start of month: " .. now:format("yyyy-MM-dd HH:mm:ss.SSS"))

-- Set to the start of the current year
now = DateTime() -- Reset
now:startOf("year")
toast("Start of year: " .. now:format("yyyy-MM-dd HH:mm:ss.SSS"))