DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

strptime(3C)


strptime -- date and time conversion

Synopsis

#include <time.h>

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

Description

strptime converts the character string pointed to by buf to values stored in the structure pointed to by tm, using the format specified by format.

format is composed of zero or more directives where each directive is composed of one of the following:

Conversion specifications

Each conversion specification is composed of a % character followed by an optional modifier and then by a conversion character which specifies the replacement required. Usually, there should be white-space or other non-alphanumeric characters between any two conversion specifications. The following conversion specifications are supported:


%a
locale's full or abbreviated weekday name

%A
same as %a

%b
locale's full or abbreviated month name

%B
same as %b

%c
locale's appropriate date and time representation (for example, %x %X)

%C
number of the century (00 - 99), leading zeros are optional

%d
day of month ( 01 - 31 ), leading zeros are optional

%D
date as %m/%d/%y

%e
same as %d

%h
same as %b

%H
hour ( 00 - 23 ), leading zeros are optional

%I
hour ( 01 - 12 ), leading zeros are optional

%j
day number of year ( 001 - 366 ), leading zeros are optional

%m
month number ( 01 - 12 ), leading zeros are optional

%M
minute ( 00 - 59 ), leading zeros are optional

%N
date and time

%n
any white space

%p
locale's equivalent of either AM or PM

%r
locale's time with 12-hour clock

%R
time as %H:%M

%S
seconds ( 00 - 61 ), allows for leap seconds, leading zeros are optional

%t
any white space

%T
time as %H:%M:%S

%U
week number of year ( 00 - 53 ), Sunday is the first day of week 1, leading zeros are optional

%w
weekday number ( 0 - 6 ), Sunday = 0, leading zeros are optional

%W
week number of year ( 00 - 53 ), Monday is the first day of week 1, leading zeros are optional

%x
locale's appropriate date representation

%X
locale's appropriate time representation

%y
year within century ( 00 - 99 ), leading zeros are optional

%Y
year as ccyy (for example, 1986)

%%
same as %

Modified conversion specifiers

Some directives can be modified by the O and E modifier characters to indicate that an alternative format or specification should be used instead of the normal directives. %O is the modifier used in association with the following conversion specifiers to specify that the locale's alternative digits be matched. The second letter has a similar effect as the letter excluding the O modifier.


%Od
the day of the month, using the locale's alternative digit symbols filled as needed with leading zeros if available, otherwise, filled with spaces.

%Oe
same as %Od

%OH
the hour (24 hour clock), using the locale's alternative digit symbols.

%OI
the hour (12 hour clock), using the locale's alternative digit symbols.

%Om
the month using the locale's alternative digit symbols.

%OM
the minutes using the locale's alternative digit symbols.

%OS
the seconds using the locale's alternative digit symbols.

%OU
the week number using the locale's alternative digit symbols (see rules for %U).

%Ow
the weekday as a number using the locale's alternative digit symbols (Sunday = 0).

%OW
the week number using the locale's alternative digit symbols (see rules for %W).

%Oy
the year (offset from %C) using the locale's alternative digit symbols.

%E is a modifier used to match the date using different era information as specified in the LC_TIME locale data file.


%Ec
the locale's alternative representation for date and time.

%EC
the locale's alternative representation for the name of the base year (period).

%Ex
the locale's alternative representation for the date.

%EX
the locale's alternative representation for the time.

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

%EY
the full alternative year representation.

A directive comprised 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 differing 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 scanned, 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 are in buf such as month or weekday names. If no match is found, strptime fails and no more characters are scanned.

Return values

Upon successful completion, strptime returns a pointer to the character following the last character parsed. Otherwise, it returns a null pointer. If not implemented, strptime returns a null pointer and sets errno to ENOSYS.

Usage

Several ````same as'''' format and the special processing of white-space characters are provided in order to ease the use of identical format strings for strftime and strptime.

References

strftime(3C), strftime(4)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004