# std::chrono::from_stream (std::chrono::gps_time)

< cpp‎ | chrono‎ | gps clock

C++
 Language Standard Library Headers Freestanding and hosted implementations Named requirements Language support library Concepts library (C++20) Diagnostics library Utilities library Strings library Containers library Iterators library Ranges library (C++20) Algorithms library Numerics library Input/output library Localizations library Regular expressions library (C++11) Atomic operations library (C++11) Thread support library (C++11) Filesystem library (C++17) Technical Specifications

Utilities library
Type support (basic types, RTTI, type traits)
Dynamic memory management
Error handling
Program utilities
Library feature-test macros
Date and time
Function objects
(C++11)
Relational operators (deprecated in C++20)
Comparisons (C++20)
Common vocabulary types
 pair tuple(C++11) apply(C++17) make_from_tuple(C++17)
 optional(C++17) any(C++17) variant(C++17)
Swap, forward and move
(C++14)
(C++11)
(C++11)
Elementary string conversions
(C++17)
(C++17)
Type operations
(C++11)
(C++17)
(C++17)

Date and time utilities
 duration(C++11) time_point(C++11) time_of_day(C++20)
 clock_time_conversion(C++20) clock_cast(C++20)
Clocks
 utc_clock(C++20) tai_clock(C++20) gps_clock(C++20) file_clock(C++20) local_t(C++20)
Calendars
 day(C++20) month(C++20) year(C++20) weekday(C++20) operator/(C++20) year_month_day(C++20) year_month_day_last(C++20) year_month_weekday(C++20) year_month_weekday_last(C++20)
 weekday_indexed(C++20) weekday_last(C++20) month_day(C++20) month_day_last(C++20) month_weekday(C++20) month_weekday_last(C++20) year_month(C++20)
Time zones
 time_zone(C++20) locate_zone(C++20) current_zone(C++20) zoned_time(C++20) link(C++20) leap(C++20)
C-style date and time

std::chrono::gps_clock
 Member functions gps_clock::now gps_clock::to_utc gps_clock::from_utc Time point I/O operator<< to_stream from_stream

 template > std::basic_istream& from_stream(std::basic_istream& is, const CharT* fmt,             std::chrono::gps_time& tp,             std::basic_string* abbrev = nullptr,             std::chrono::minutes* offset = nullptr); (since C++20)

Attempts to parse the input stream is into the time point tp according to the format string fmt.

Behaves as an UnformattedInputFunction, except that it has an unspecified effect on is.gcount(). After constructing and checking the sentry object, attempts to parse the input stream is into tp according to the format string fmt. If the parse fails to decode a valid time point, is.setstate(std::ios_base::failbit) is called and tp is not modified.

If the format specifier %Z is used and successfully parsed, the parsed value is assigned to *abbrev if abbrev is not null. If the format specifier %z or a modified variant is used and successfully parsed, the parsed value is assigned to *offset if offset is not null, and the parsed offset will be subtracted from the parsed timestamp before the difference is assigned to tp.

### Format string

The format string consists of zero or more conversion specifiers and ordinary characters. Each ordinary character, excluding whitespace characters and the terminating null character, matches one identical character from the input stream, or causes the function to fail if the next character on the stream does not compare equal.

Each whitespace character matches zero or more whitespace characters in the input stream.

Each unmodified conversion specifier begins with a % character followed by a character that determines the behavior of the specifier. Some conversion specifiers have a modified form in which an E or O modifier character is inserted after the % character. Some conversion specifiers have a modified form in which a width parameter given as a positive decimal integer (shown as N below) is inserted after the % character. Each conversion specifier causes the matched characters to be interpreted as parts of date and time types according to the table below.

A character sequence in the format string that begins with a % but does not match one of the conversion specifiers below is interpreted as ordinary characters.

If from_stream fails to parse everything specified by the format string, or if insufficient information is parsed to specify a complete result, or if parsing discloses contradictory information, is.setstate(std::ios_base::failbit) is called.

The following conversion specifiers are available:

Conversion
specifier
Explanation
%% Matches a literal % character.
%n Matches one whitespace character.
%t Matches zero or one whitespace character.
Year
%C
%NC
%EC
%OC
Parses the century as a decimal number. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required.

The modified commands %EC and %OC interpret the locale's alternative representation of the century.

%y
%Ny
%Ey
%Oy
Parses the last two decimal digits of the year. If the century is not otherwise specified (e.g. with %C), values in the range [69, 99] are presumed to refer to the years 1969 to 1999, and values in the range [00, 68] are presumed to refer to the years 2000 to 2068. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required.

The modified commands %Ey and %Oy interpret the locale's alternative representation.

%Y
%NY
%EY
Parses the year as a decimal number. The width N specifies the maximum number of characters to read. The default width is 4. Leading zeroes are permitted but not required.

The modified command %EY interprets the locale's alternative representation.

Month
%b
%B
%h
Parses the locale's full or abbreviated case-insensitive month name.
%m
%Nm
%Om
Parses the month as a decimal number (January is 1). The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required.

The modified command %Om interprets the locale's alternative representation.

Day
%d
%Nd
%Ed
%e
%Ne
%Ee
Parses the day of month as a decimal number. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required.

The modified commands %Ed and %Ee interpret the locale's alternative representation.

Day of the week
%a
%A
Parses the locale's full or abbreviated case-insensitive weekday name.
%u
%Nu
%Ou
Parses the ISO weekday as a decimal number (1-7), where Monday is 1. The width N specifies the maximum number of characters to read. The default width is 1. Leading zeroes are permitted but not required.

The modified command %Ou interprets the locale's alternative representation.

%w
%Nw
%Ow
Parses the weekday as a decimal number (0-6), where Sunday is 0. The width N specifies the maximum number of characters to read. The default width is 1. Leading zeroes are permitted but not required.

The modified command %Ow interprets the locale's alternative representation.

ISO 8601 week-based year

In ISO 8601 weeks begin with Monday and the first week of the year must satisfy the following requirements:

• Includes January 4
• Includes first Thursday of the year
%g
%Ng
Parses the last two decimal digits of the ISO 8601 week-based year. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required.
%G
%NG
Parses the ISO 8601 week-based year as a decimal number. The width N specifies the maximum number of characters to read. The default width is 4. Leading zeroes are permitted but not required.
%V
%NV
Parses the ISO 8601 week of the year as a decimal number. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required.
Week/day of the year
%j
%Nj
Parses the day of the year as a decimal number (January 1 is 1). The width N specifies the maximum number of characters to read. The default width is 3. Leading zeroes are permitted but not required.
%U
%NU
Parses the week number of the year as a decimal number. The first Sunday of the year is the first day of week 01. Days of the same year prior to that are in week 00. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required.
%W
%NW
Parses the week number of the year as a decimal number. The first Monday of the year is the first day of week 01. Days of the same year prior to that are in week 00. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required.
Date
%D Equivalent to "%m/%d/%y".
%F
%NF
Equivalent to "%Y-%m-%d". If the width is specified, it is only applied to the %Y.
%x
%Ex
Parses the locale's date representation.

The modified command %Ex interprets the locale's alternate date representation.

Time of day
%H
%NH
%OH
Parses the hour (24-hour clock) as a decimal number. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required.

The modified command %OH interprets the locale's alternative representation.

%I
%NI
Parses the hour (12-hour clock) as a decimal number. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required.
%M
%NM
%OM
Parses the minute as a decimal number. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required.

The modified command %OM interprets the locale's alternative representation.

%S
%NS
%OS
Parses the second as a decimal number. The width N specifies the maximum number of characters to read. The default width is 2 if Duration is convertible to std::chrono::seconds, otherwise it is determined by the decimal precision of Duration and the field is interpreted as a long double in a fixed format, with the decimal point character determined by the locale (if encountered). Leading zeroes are permitted but not required.

The modified command %OS interprets the locale's alternative representation.

%p Parses the locale's equivalent of the AM/PM designations associated with a 12-hour clock. The command %I must precede %p in the format string.
%R Equivalent to "%H:%M".
%T Equivalent to "%H:%M:%S".
%r Parses the locale's 12-hour clock time.
%X
%EX
Parses the locale's time representation.

The modified command %EX interprets the locale's alternate time representation.

Miscellaneous
%c
%Ec
Parses the locale's date and time representation.

The modified command %Ec interprets the locale's alternative date and time representation.

%z
%Ez
%Oz
Parses the offset from UTC in the format [+|-]hh[mm]. For example -0430 refers to 4 hours 30 minutes behind UTC and 04 refers to 4 hours ahead of UTC.

The modified commands %Ez and %Oz parses the format [+|-]h[h][:mm] (i.e., requiring a : between the hours and minutes and making the leading zero for hour optional).

%Z Parses the time zone abbreviation or name, taken as the longest sequence of characters that only contains the characters A through Z, a through z, 0 through 9, -, +, _, and /.

### Return value

is.

 parse(C++20) parses a chrono object from a stream (function template)