Skip to main content
Version: Next

format_time

Formats a time into a string that follows a specific format.

format_time(input: time, format: string) -> string

Description

The format_time function formats the given input time into a string by using the given format.

input: time

The input time for which a string should be constructed.

format: string

The string that specifies the desired output format, for example "%m-%d-%Y". The allowed format specifiers are the same as for strftime(3):

SpecifierDescription
%aAbbreviated name of the day of the week (locale-specific).
%AFull name of the day of the week (locale-specific).
%bAbbreviated month name (locale-specific).
%BFull month name (locale-specific).
%cPreferred date and time representation for the current locale.
%CCentury number (year/100) as a 2-digit integer.
%dDay of the month as a decimal number (01–31).
%DEquivalent to %m/%d/%y.
%eDay of the month as a decimal number with a leading space instead of zero.
%EModifier for alternative ("era-based") format.
%FISO 8601 date format (%Y-%m-%d).
%GISO week-based year with century.
%gISO week-based year without century (2 digits).
%hEquivalent to %b.
%HHour (24-hour clock) as a decimal number (00–23).
%IHour (12-hour clock) as a decimal number (01–12).
%jDay of the year as a decimal number (001–366).
%kHour (24-hour clock) as a decimal number with leading space (0–23).
%lHour (12-hour clock) as a decimal number with leading space (1–12).
%mMonth as a decimal number (01–12).
%MMinute as a decimal number (00–59).
%nNewline character.
%OModifier for alternative numeric symbols.
%pAM/PM or corresponding strings for the current locale.
%PLike %p, but lowercase (e.g., "am", "pm").
%rTime in a.m./p.m. notation (locale-specific).
%RTime in 24-hour notation (%H:%M).
%sSeconds since the Unix Epoch (1970-01-01 00:00:00 UTC).
%SSecond as a decimal number (00–60, allowing leap seconds).
%tTab character.
%TTime in 24-hour notation (%H:%M:%S).
%uDay of the week as a decimal number (1=Monday, 7=Sunday).
%UWeek number of the year (starting Sunday, range 00–53).
%VISO 8601 week number (range 01–53).
%wDay of the week as a decimal number (0=Sunday, 6=Saturday).
%WWeek number of the year (starting Monday, range 00–53).
%xPreferred date representation for the current locale.
%XPreferred time representation for the current locale.
%yYear without century as a decimal number (00–99).
%YYear with century as a decimal number.
%zNumeric timezone offset from UTC (+hhmm or -hhmm).
%ZTimezone name or abbreviation.
%+Date and time in date(1) format.
%%Literal % character.

Examples

Format a timestamp

from {
  x: 2024-12-31T12:59:42,
}
x = x.format_time("%d.%m.%Y")
{x: "31.12.2024"}

See Also

parse_time