Skip to content

format_time

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

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

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

The input time for which a string should be constructed.

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

SpecifierDescriptionExample
%%A literal % character%
%aAbbreviated or full weekday nameMon, Monday
%AEquivalent to %aMon, Monday
%bAbbreviated or full month nameJan, January
%BEquivalent to %bJan, January
%cDate and time representationMon Jan 1 12:00:00 2024
%CCentury as a decimal number20
%dDay of the month with zero padding01, 31
%DEquivalent to %m/%d/%y01/31/24
%eDay of the month with space padding 1, 31
%FEquivalent to %Y-%m-%d2024-01-31
%gLast two digits of ISO week-based year24
%GISO week-based year2024
%hEquivalent to %bJan
%HHour in 24-hour format00, 23
%IHour in 12-hour format01, 12
%jDay of year001, 365
%mMonth number01, 12
%MMinutes00, 59
%nNewline character\n
%pAM/PM designationAM, PM
%r12-hour clock time12:00:00 PM
%REquivalent to %H:%M23:59
%SSeconds00, 59
%tTab character\t
%TEquivalent to %H:%M:%S23:59:59
%uISO weekday (Monday=1)1, 7
%UWeek number (Sunday as first day)00, 52
%VISO week number01, 53
%wWeekday (Sunday=0)0, 6
%WWeek number (Monday as first day)00, 52
%xDate representation01/31/24
%XTime representation23:59:59
%yYear without century24
%YYear with century2024
%zUTC offset+0000, -0430
%ZTime zone abbreviationUTC, EST
from {
x: 2024-12-31T12:59:42,
}
x = x.format_time("%d.%m.%Y")
{x: "31.12.2024"}

parse_time

Last updated: