Aller au contenu principal

DateTime():format()

Returns the formatted date as a string.

Signature

format(pattern: string): string
format(): string

Parameters

ParameterTypeDescription
pattern (Optional)stringThe format pattern to apply. If not provided, a default format is used. Accepted formats include:yyyy-MM-dd'T'HH:mm:ss.SSSZ, yyyy-MM-dd'T'HH:mm:ssZ, yyyy-MM-dd'T'HH:mm:ss, yyyy-MM-dd HH:mm:ss, yyyy-MM-dd, MM/dd/yyyy, dd/MM/yyyy, yyyy/MM/dd

Returns

  • Type: string
  • The formatted date string.

Examples

local now = DateTime()

-- Format with a specific pattern
local formattedDate1 = now:format("yyyy-MM-dd HH:mm:ss")
toast("Formatted Date (yyyy-MM-dd HH:mm:ss): " .. formattedDate1)

-- Format with a different pattern
local formattedDate2 = now:format("MM/dd/yyyy")
toast("Formatted Date (MM/dd/yyyy): " .. formattedDate2)

-- Format with default pattern (if no pattern is provided)
local formattedDate3 = now:format()
toast("Formatted Date (default): " .. formattedDate3)