Skip to main content

Date.format

formatformat

Group: Conversions

Documentation

Format this date using the provided format specifier.

Arguments

  • format: A pattern describing how to format the text, or a Date_Time_Formatter.

Examples

Format "2020-06-02" as "2 Jun 2020"

      from Standard.Base import Date

example_format = Date.new 2020 6 2 . format "d MMMM yyyy"

Format "2020-06-02" as "2 Jun 20"

      example_format = Date.new 2020 6 2 . format "d MMMM yy"

Format "2020-06-02" as "Tuesday, 02 Jun 2020"

      example_format = Date.new 2020 6 2 . format "EEEE, dd MMMM yyyy"

Format "2020-06-02" as "Tue Jun 2"

      example_format = Date.new 2020 6 2 . format "EEE MMM d"

Format "2020-06-02" as "2020AD"

      example_format = Date.new 2020 6 2 . format "yyyyGG"

Format "2020-06-21" with French locale as "21. juin 2020"

      example_format = Date.new 2020 6 21 . format (Date_Time_Formatter.from "d. MMMM yyyy" (Locale.new "fr"))

Remarks

Pattern Syntax

If the pattern is provided as Text, it is parsed using the format described below. See Date_Time_Formatter for more options.

  • y: Year. The number of pattern letters determines the minimum number of digits.
    • y: The year using any number of digits.
    • yy: The year, using at most two digits. The default range is 1950-2049, but this can be changed by including the end year in braces e.g. yy{2099}.
    • yyyy: The year, using exactly four digits.
  • M: Month of year. The number of pattern letters determines the format:
    • M: Any number (1-12).
    • MM: Month number with zero padding required (01-12).
    • MMM: Short name of the month (Jan-Dec).
    • MMMM: Full name of the month (January-December). The month names depend on the selected locale.
  • d: Day. The number of pattern letters determines the format:
    • d: Any number (1-31).
    • dd: Day number with zero padding required (01-31).
    • ddd: Short name of the day of week (Mon-Sun).
    • dddd: Full name of the day of week (Monday-Sunday). The weekday names depend on the selected locale. Both day of week and day of month may be included in a single pattern - in such case the day of week is used as a sanity check.
  • Q: Quarter of year. If only year and quarter are provided in the pattern, when parsing a date, the result will be the first day of that quarter.