Aller au contenu principal

DateTime():format()

Renvoie la date formatée sous forme de chaîne.

Signature

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

Paramètres

ParamètreTypeDescription
pattern (Optionnel)stringLe modèle de format à appliquer. S'il n'est pas fourni, un format par défaut est utilisé. Les formats acceptés incluent :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

Renvoie

  • Type : string
  • La chaîne de date formatée.

Exemples

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)