Skip to content

parse_time

Parses a time from a string that follows a specific format.

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

The parse_time function matches the given input string against the format to construct a timestamp.

The input string from which the timestamp should be extracted.

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

SpecifierDescriptionExample
%%A literal % character%
%aAbbreviated weekday nameMon
%AFull weekday nameMonday
%bAbbreviated month nameJan
%BFull month nameJanuary
%cDate and time representationMon Jan 1 12:00:00 2024
%CCentury (year divided by 100)20
%dDay of month with zero padding01, 31
%DEquivalent to %m/%d/%y01/31/24
%eDay of 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
%MMinute00, 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-31+12:59:42",
}
x = x.parse_time("%Y-%m-%d+%H:%M:%S")
{x: 2024-12-31T12:59:42.000000}

format_time

Last updated: