DateFormat

Package: Libraries.System · Inherits from: Libraries.Language.Object

The DateFormat class writes a CalendarDate as text, and reads text back into a CalendarDate, by a pattern such as "MMMM d, yyyy" ("November 12, 2026"), "MM/dd/yyyy" ("11/12/2026") or "yyyy-MM-dd" ("2026-11-12"). The pattern's letters are those of the Unicode date format patterns (Unicode Technical Standard #35), which most platforms follow: yyyy: the year, such as 2026 (yy is its last two digits). M: the month's number, such as 1 or 11. MM: two digits, such as 01. MMM: the month's short name, such as "Nov". MMMM: its name, "November". d: the day of the month, such as 3. dd: two digits, such as 03. EEE: the weekday's short name, such as "Thu". EEEE: its name, "Thursday". Any other character is written as it is. Text in single quotes is written as it is too, even letters, and two single quotes are one quote. The month and weekday names are English unless set with SetMonthNames and SetDayNames, so a format for another language is a pattern with other names. A short name is the first three letters of the name.

Example Code

use Libraries.System.CalendarDate
use Libraries.System.DateFormat

DateFormat format
format:SetPattern("EEEE, MMMM d, yyyy")
CalendarDate date
date:SetDate(2026, 11, 12)
output format:ToText(date)

CalendarDate typed = format:Parse("Friday, November 13, 2026")
if typed not= undefined
    output typed:ToText()
end

Actions

GetISOFormat()

This action returns a new format for ISO 8601 dates, "yyyy-MM-dd", such as "2026-11-12", with this format's names.

Returns

Libraries.System.DateFormat: The ISO format.

Example

use Libraries.System.DateFormat

DateFormat formats
DateFormat iso = formats:GetISOFormat()

GetLongFormat()

This action returns a new format for long dates, "MMMM d, yyyy", such as "November 12, 2026", with this format's names. This is the pattern a new DateFormat has.

Returns

Libraries.System.DateFormat: The long format.

Example

use Libraries.System.DateFormat

DateFormat formats
DateFormat long = formats:GetLongFormat()

GetNumericFormat()

This action returns a new format for dates as numbers, "MM/dd/yyyy", such as "11/12/2026", with this format's names.

Returns

Libraries.System.DateFormat: The numeric format.

Example

use Libraries.System.DateFormat

DateFormat formats
DateFormat numeric = formats:GetNumericFormat()

GetPattern()

This action returns the pattern dates are written and read with.

Returns

text: The pattern, such as "MMMM d, yyyy".

Example

use Libraries.System.DateFormat

DateFormat format
output format:GetPattern()

Parse(text value)

This action reads a date from text in this format, or returns undefined if the text isn't a date in this format, such as "November 31, 2026" or "tomorrow". Names are read with any case, in full or short ("nov 12, 2026"), numbers with or without zeros in front, and spaces in the pattern match any number of spaces. Space before and after the date is ignored. A pattern with no year reads dates in 1970; with no month, January; with no day, the first.

Parameters

  • value text: The text to read.

Returns

Libraries.System.CalendarDate: The date, or undefined.

Example

use Libraries.System.CalendarDate
use Libraries.System.DateFormat

DateFormat format
format:SetPattern("MM/dd/yyyy")
CalendarDate date = format:Parse("11/12/2026")

SetDayNames(Libraries.Containers.Array<text> names)

This action sets the seven weekday names, Monday first, for another language. The short names are their first three letters. An array that doesn't have seven names is ignored.

Parameters

Example

use Libraries.System.DateFormat
use Libraries.Containers.Array

Array<text> names
names:Add("lunes")
names:Add("martes")
names:Add("miércoles")
names:Add("jueves")
names:Add("viernes")
names:Add("sábado")
names:Add("domingo")
DateFormat format
format:SetDayNames(names)

SetMonthNames(Libraries.Containers.Array<text> names)

This action sets the twelve month names, January first, for another language. The short names are their first three letters. An array that doesn't have twelve names is ignored.

Parameters

Example

use Libraries.System.DateFormat
use Libraries.Containers.Array

Array<text> names
names:Add("enero")
names:Add("febrero")
names:Add("marzo")
names:Add("abril")
names:Add("mayo")
names:Add("junio")
names:Add("julio")
names:Add("agosto")
names:Add("septiembre")
names:Add("octubre")
names:Add("noviembre")
names:Add("diciembre")
DateFormat format
format:SetPattern("d 'de' MMMM 'de' yyyy")
format:SetMonthNames(names)

SetPattern(text newPattern)

This action sets the pattern dates are written and read with, such as "MMMM d, yyyy" or "MM/dd/yyyy". The letters are described with the class. A new DateFormat uses "MMMM d, yyyy".

Parameters

  • newPattern text: The pattern.

Example

use Libraries.System.DateFormat

DateFormat format
format:SetPattern("dd.MM.yyyy")

ToText(Libraries.System.CalendarDate date)

This action writes a date as text in this format. An undefined date is an empty text.

Parameters

Returns

text: The date as text, such as "November 12, 2026".

Example

use Libraries.System.CalendarDate
use Libraries.System.DateFormat

DateFormat format
CalendarDate date
date:SetDate(2026, 11, 12)
output format:ToText(date)

Inherited Actions

3 actions from Libraries.Language.Object