Skip to main content
Version: Next

parse_time

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

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

Description

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

input: string

The input string from which the timestamp should be extracted.

format: string

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

SpecifierDescription
%%The % character.
%a/%ADay name in abbreviated or full form.
%b/%B/%hMonth name in abbreviated or full form.
%cDate and time representation for the locale.
%CCentury number (0–99).
%d/%eDay of the month (1–31).
%DEquivalent to %m/%d/%y (American style).
%HHour (0–23).
%IHour on a 12-hour clock (1–12).
%jDay number in the year (1–366).
%mMonth number (1–12).
%MMinute (0–59).
%nArbitrary whitespace.
%pLocale's equivalent of AM or PM.
%r12-hour clock time, e.g., %I:%M:%S %p.
%REquivalent to %H:%M.
%SSecond (0–60, leap seconds included).
%tArbitrary whitespace.
%TEquivalent to %H:%M:%S.
%UWeek number (Sunday as the first day, 0–53).
%wOrdinal day of the week (0–6, Sunday=0).
%WWeek number (Monday as the first day, 0–53).
%xDate in the locale's format.
%XTime in the locale's format.
%yYear within the century (0–99).
%YFull year (e.g., 1991).
%EcLocale's alternative date and time.
%ECBase year name in alternative representation.
%ExLocale's alternative date.
%EXLocale's alternative time.
%EyYear offset from %EC.
%EYFull alternative year.
%Od/%OeDay of month with alternative numeric symbols.
%OHHour (24-hour clock) in alternative numeric symbols.
%OIHour (12-hour clock) in alternative numeric symbols.
%OmMonth with alternative numeric symbols.
%OMMinutes with alternative numeric symbols.
%OSSeconds with alternative numeric symbols.
%OUWeek number (Sunday as first day) in alternative numeric symbols.
%OwOrdinal day of the week in alternative numeric symbols.
%OWWeek number (Monday as first day) in alternative numeric symbols.
%OyYear offset in alternative numeric symbols.

Examples

Parse a timestamp

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}

See Also

format_time