strptime(), strptime_l()

convert string to time values 

Function


SYNOPSIS

#include <time.h>

char *strptime(const char *buf, const char *format, struct tm *tm);

#include <time.h>

#include <locale.h>

char *strptime_l(const char *buf, const char *format, struct tm *tm, locale_t locale);


DESCRIPTION

The strptime() and strptime_l() functions converts the specified character string to time values, using the specified format. The format string contains zero or more directives. Each directive is composed of one of the following: one or more white-space characters (as specified by isspace() or isspace_l()); an ordinary character (neither '%' nor a white-space character); or a conversion specification. A conversion specification consists of a % character and one or more characters that determine the behavior. There must be white-space or other non-alphanumeric characters between any two conversion specifications. The following conversion specifications are implemented.

%a  

is the day of the week, using the locale's weekday names; either the abbreviated or full name may be specified.

%A  

is the same as %a.

%b  

is the month, using the locale's month names; either the abbreviated or full name may be specified.

%B  

is the same as %b.

%c  

is replaced by the locale's appropriate date and time representation.

%C  

is the century number [0,99]; leading zeros are permitted by not required.

%d  

is the day of the month [1,31]; leading zeros are permitted but not required.

%D  

is the same as %m/%d/%y.

%e  

is the same as %d.

%h  

is the same as %b.

%H  

is the hour (24-hour clock) [0,23]; leading zeros are permitted but not required.

%I  

is the hour (12-hour clock) [1-12]; leading zeros are permitted but not required.

%j  

is the day of the year [1,366]; leading zeros are permitted but not required.

%k  

is the same as %H

%l  

is the same as %I.

%m  

is the month number [1-12]; leading zeros are permitted but not required.

%M  

is the minute [0-59]; leading zeros are permitted but not required.

%n  

is any white space.

%p  

is the locale's equivalent of either A.M./P.M. indicator for 12-hour clock.

%r  

is the time as %I:%M:%S %p.

%R  

is the time as %H:%M.

%S  

is the seconds [0-61]; leading zeros are permitted but not required.

%t  

is any white space.

%T  

is the time as %H:%M:%S.

%U  

is the week number of the year (Sunday as the first day of the week) as a decimal number [0-53]; leading zeros are permitted but not required.

%w  

is the weekday as a decimal number [0,6], with 0 representing Sunday; leading zeros are permitted but not required.

%W  

is the week number of the year (Monday as the first day of the week) as a decimal number [0,53]; leading zeros are permitted but not required.

%x  

is the date, using the locale's date format.

%X  

is the time, using the locale's time format.

%y  

is the year within the century. When a century is not otherwise specified, values in the range 69-99 refer to years in the twentieth century (1969 to 1999 inclusive); values in the range 0-68 refer to years in the twenty-first century (2000-2068 inclusive). Leading zeros are permitted but not required.

%Y  

is the year including the century (for example, 1998).

%%  

is replaced by %.

Some conversion specifiers can be modified by the E or O modifier characters to indicate that an alternative format of specification should be used rather that the one normally used by the unmodified conversion specifier. If the alternative format or specification does not exist for he current locale, the behavior is as if the unmodified conversion specification were used. It is an error to specify the E or O modifier with any conversion specification not listed here.

%Ec  

is the locale's alternative date and time representation.

%EC  

is the name of the base year (period) in the locale's alternative representation.

%Ex  

is the locale's alternative date representation.

%EX  

is the locale's alternative time representation.

%Ey  

is the offset from %EC (year only) in the locale's alternative representation.

%EY  

is the full alternative year representation.

%Od  

is the day of the month, using the locale's alternative numeric symbols; leading zeros are permitted but not required.

%Oe  

is the same as %Od.

%OH  

is the hour in 24-hour format using the locale's alternative numeric symbols.

%OI  

is the hour in 12-hour format using the locale's alternative numeric symbols.

%Om  

is the month using the locale's alternative numeric symbols

%OM  

is the minutes using the locale's alternative numeric symbols.

%OS  

is the seconds using the locale's alternative numeric symbols.

%OU  

is the week number of the year (Sunday as the first day of the week, rules corresponding to %U) using the locale's alternative numeric symbols.

%Ow  

is the number of the weekday using the locale's alternative numeric symbols, with 0 representing Sunday.

%OW  

is the week number of the year (Monday as the first day of the week) using the locale's alternative numeric symbols.

%Oy  

is the year (offset from %C) using the locale's alternative numeric symbols.

The # character may be used with any conversion specifier. In that case, the meaning of the format code is changed as follows (if an alternate representation is not listed, the modifier is ignored for that conversion specifier):

%#c  

is the locale's date and time representation, in long format (that is, using the full rather than abbreviated weekday and month names).

%#x  

is the locale's date representation, in long format (that is, using the full rather than the abbreviated weekday and month names).

%#d, %#H, %#I, %#j, %#m, %#M, %#S, %#U, %#w, %#W, %#y, %#Y  

are replaced as described above, with any leading zeros removed.

A directive composed of white-space characters is executed by scanning input up to the first character that is not white-space (which remains unscanned), or until no more characters can be scanned.

A directive that is an ordinary character is executed by scanning the next character from the buffer. If the character scanned from the buffer differs from the one comprising the directive, the directive fails, and the different and subsequent characters remain unscanned.

A series of directives composed of %n, %t, white-space characters, or any combination is executed by scanning up to the first character that is not white space (which remains unscanned), or until no more characters can be scanned.

Any other conversion specification is executed by scanning characters until a character matching the next directive is canned, or until no more characters can be scanned. These characters, except the one matching the next directive, are then compared to the locale values associated with the conversion specifier. If a match is found, values for the appropriate tm structure members are set to values corresponding to the locale information. Case is ignored when matching items such as month or weekday names. If no match can be found, strptime() and strptime_l() fail and no more characters are scanned.


PARAMETERS

buf 

Is the buffer containing the time specification.

format 

Is the format specification for the conversion.

tm 

Points to the resulting converted time.

locale 

Is a locale_t perhaps returned by newlocale() or LC_GLOBAL_LOCALE or 0 for the current thread locale set with uselocale().


RETURN VALUES

If successful, strptime() and strptime_l() return a pointer to the character following the last character parsed. Otherwise, a null pointer is returned.


CONFORMANCE

strptime() conforms to UNIX 98, with exceptions.

strptime_l() conforms to IEEE Std 1003.1-2008 'POSIX.1'.


MULTITHREAD SAFETY LEVEL

MT-Safe, with exceptions.

The function strptime() is MT-Safe as long as no thread calls setlocale() while this function is executing.

The function strptime_l() is MT-Safe as long as no thread calls freelocale() on locale while this function is executing.


PORTING ISSUES

The NuTCRACKER Platform locale conversions are based on the native Windows implementations. The Windows locale databases do not provide alternative time representations. Hence the E and O modifiers are always ignored. The # modifier is provided for compatibility with the Visual C++ runtime library implementation of strftime().


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
isspace(), isspace_l(), strftime(), strftime_l(), time()


PTC MKS Toolkit 10.4 Documentation Build 39.