Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ strptime(3C) — HP-UX 9.10

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

scanf(3S)

strftime(3C)

getdate(3C)

ctime(3C)

setlocale(3C)

strptime(3C)  —  Series 300/400

 

NAME

strptime − date and time conversion
 

SYNOPSIS

#include <time.h>

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

DESCRIPTION

The strptime() function converts the character string pointed to by buf to values which are stored in the tm structure pointed to by tm, using the format specified by format. 

The format is composed of zero or more directives. Each directive is composed of one of the following: one or more white-space characters (as specified by the isspace() function), an ordinary character (neither % nor a white-space character), or a conversion specification. Each conversion specification is composed of a % character followed by a conversion character which specifies the replacement required. There must be white-space or other non-alphanumeric characters between any two conversion specifications. The following conversion specifications are supported:
 

%a is the day of 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 the date and time, using locale’s date format (for example, as %x %X). 

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

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

%D is the date 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 number of the year [1,366]; leading zeros are permitted but not required. 

%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 a.m or p.m.. 

%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.  All days in a year preceding the first Sunday are considered to be in week 0. 

%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.  All days in a year preceding the first Monday are considered to be in week 0. 

%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 [0,99]; leading zeros are permitted but not required. 

%Y is the year, including the century (for example, 1992). 

%% is replaced by %. 

The field descriptors %c, %x, and %X are not supported if they include unsupported field descriptors. 

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 differing and subsequent characters remain unscanned. 

A series of directives composed of %n, %t, white-space characters or any combination thereof 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 in buf such as month or weekday names. If no match is found, strptime() fails and no more characters are scanned. 
 

EXTERNAL INFLUENCES

Locale

The LC_TIME category determines the characters to be interpreted for those directives described above as being from the locale. 

The LC_CTYPE category determines the interpretation of the bytes within format as single and/or multi-byte characters. 

International Code Set Support

Single- and multi-byte character code sets are supported. 
 

RETURN VALUE

Upon successful completion, strptime() returns a pointer to the character following the last character parsed.  Otherwise, a null pointer is returned. 
 

EXAMPLES

The following program segment uses strptime() to convert the string (first argument) to values according to the format specified in the second argument. 

struct tm t;
setlocale(LC_TIME, "american");
strptime("1:04:23 PM on 10/6/92", "%I:%M:%S %p on %D", &t);

The converted value is stored in the structure t as follows:

t.tm_sec   = 23
t.tm_min   = 4
t.tm_hour  = 13
t.tm_mday  = 6
t.tm_mon   = 9
t.tm_year  = 92
t.tm_wday  = 2
t.tm_yday  = 279
t.tm_isdst = 1

 

AUTHOR

strptime was developed by HP. 
 

SEE ALSO

scanf(3S), strftime(3C), getdate(3C), ctime(3C), setlocale(3C). 
 

STANDARDS CONFORMANCE

strptime: XPG4

Hewlett-Packard Company  —  HP-UX Release 9.10: April 1995

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026