DateTime():format()
Gibt das formatierte Datum als Zeichenkette zurück.
Signatur
format(pattern: string): string
format(): string
Parameter
| Parameter | Typ | Beschreibung |
|---|---|---|
pattern (Optional) | string | Das anzuwendende Formatmuster. Wird es nicht angegeben, wird ein Standardformat verwendet. Akzeptierte Formate umfassen: 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 |
Rückgabe
- Typ:
string - Die formatierte Datumszeichenkette.
Beispiele
local now = DateTime()
-- Mit einem bestimmten Muster formatieren
local formattedDate1 = now:format("yyyy-MM-dd HH:mm:ss")
toast("Formatiertes Datum (yyyy-MM-dd HH:mm:ss): " .. formattedDate1)
-- Mit einem anderen Muster formatieren
local formattedDate2 = now:format("MM/dd/yyyy")
toast("Formatiertes Datum (MM/dd/yyyy): " .. formattedDate2)
-- Mit Standardmuster formatieren (wenn kein Muster angegeben wird)
local formattedDate3 = now:format()
toast("Formatiertes Datum (Standard): " .. formattedDate3)