<time.h>
#define CLOCKS_PER_SEC
<integer constant expression > 0>
#define NULL
<either 0, 0L, or (void *)0> [0 in C++]
char *asctime(const
struct tm *tptr);
clock_t clock(void);
typedef a-type clock_t;
char *ctime(const time_t *tod);
double difftime(time_t t1,
time_t t0);
struct tm
*gmtime(const time_t *tod);
struct tm
*localtime(const time_t *tod);
time_t mktime(struct tm *tptr);
typedef ui-type size_t;
size_t strftime(char *s,
size_t n, const char *format, const struct tm *tptr);
time_t time(time_t *tod);
typedef a-type time_t;
struct tm;
Include the standard header <time.h>
to declare several
functions that help you manipulate times. The following diagram
summarizes the functions and the object types that they convert
between
The functions share two static-duration objects that hold values computed by the functions:
struct tm
A call to one of these functions can alter the value that was stored earlier in a static-duration object by another of these functions.
CLOCKS_PER_SEC
#define CLOCKS_PER_SEC
<integer constant expression > 0>
The macro yields the number of clock ticks,
returned by clock
, in one second.
NULL
#define NULL <either 0, 0L, or (void *)0>
[0 in C++]
The macro yields a null pointer constant that is usable as an address constant expression.
asctime
char *asctime(const struct tm *tptr);
The function stores in the static-duration time string a 26-character
English-language representation of the time encoded in *tptr
.
It returns the address of the static-duration
time string. The text
representation takes the form:
Sun Dec 2 06:55:15 1979\n\0
clock
clock_t clock(void);
The function returns the number of clock ticks of elapsed processor time, counting from a time related to program startup, or it returns -1 if the target environment cannot measure elapsed processor time.
clock_t
typedef a-type clock_t;
The type is the arithmetic type a-type
of an object that you declare to hold the value returned by
clock
, representing
elapsed processor time.
ctime
char *ctime(const time_t *tod);
The function converts the calendar time in *tod
to a
text representation of the local time in the static-duration
time string.
It returns the address of that string. It is equivalent to
asctime(localtime(tod))
.
difftime
double difftime(time_t t1, time_t t0);
The function returns the difference t1 - t0
, in seconds,
between the calendar time t0
and the calendar time t1
.
gmtime
struct tm *gmtime(const time_t *tod);
The function stores in the static-duration
time structure an
encoding of the calendar time in *tod
, expressed as
Universal Time Coordinated, or UTC.
(UTC was formerly Greenwich Mean Time, or GMT).
It returns the address of that structure.
localtime
struct tm *localtime(const time_t *tod);
The function stores in the static-duration
time structure an
encoding of the calendar time in *tod
, expressed as local time.
It returns the address of that structure.
mktime
time_t mktime(struct tm *tptr);
The function alters the values stored in *tptr
to represent
an equivalent encoded local time, but with the values of all members
within their normal ranges.
It then determines the values tptr->wday
and tptr->yday
from the values of the other members.
It returns the calendar time equivalent to the encoded time, or it returns a
value of -1 if the calendar time cannot be represented.
size_t
typedef ui-type size_t;
The type is the unsigned integer type ui-type
of an object that you declare to store the result of the
sizeof operator.
strftime
size_t strftime(char *s, size_t n, const char *format,
const struct tm *tptr);
The function generates formatted text, under the control of
the format format
and the values stored in the time structure
*tptr
. It stores each generated character
in successive locations of the array object of size
n
whose first element has the address s
.
The function then stores a null character in the next location
of the array. It returns x
, the number of characters generated,
if x < n
; otherwise, it returns zero, and the
values stored in the array are indeterminate.
For each multibyte character other than %
in the format,
the function stores that multibyte character in the array object.
Each occurrence of %
followed by
another character in the format is a
conversion specifier.
For each conversion specifier, the
function stores a replacement character sequence.
The following table lists all conversion specifiers
defined for strftime
. Example replacement character sequences
in parentheses follow each conversion specifier. All examples are for the
"C"
locale,
using the date and time Sunday, 2 December 1979 at 06:55:15 AM EST.
%a abbreviated weekday name (Sun) %A full weekday name (Sunday) %b abbreviated month name (Dec) %B full month name (December) %c date and time (Dec 2 06:55:15 1979) %d day of the month (02) %H hour of the 24-hour day (06) %I hour of the 12-hour day (06) %j day of the year, from 001 (335) %m month of the year, from 01 (12) %M minutes after the hour (55) %p AM/PM indicator (AM) %S seconds after the minute (15) %U Sunday week of the year, from 00 (48) %w day of the week, from 0 for Sunday (6) %W Monday week of the year, from 00 (47) %x date (Dec 2 1979) %X time (06:55:15) %y year of the century, from 00 (79) %Y year (1979) %Z time zone name, if any (EST) %% percent character %
The current
locale category
LC_TIME
can affect these
replacement character sequences.
time
time_t time(time_t *tod);
If tod
is not a null pointer, the function stores the
current calendar time in *tod
. The function returns the current
calendar time, if the target environment can determine it; otherwise,
it returns -1.
time_t
typedef a-type time_t;
The type is the arithmetic type a-type
of an object that you declare to hold
the value returned by time
.
The value represents calendar time.
tm
struct tm { int tm_sec; seconds after the minute (from 0) int tm_min; minutes after the hour (from 0) int tm_hour; hour of the day (from 0) int tm_mday; day of the month (from 1) int tm_mon; month of the year (from 0) int tm_year; years since 1900 (from 0) int tm_wday; days since Sunday (from 0) int tm_yday; day of the year (from 0) int tm_isdst; Daylight Saving Time flag };
struct tm
contains members that describe various
properties of the calendar time. The members shown above can occur
in any order, interspersed with additional members. The comment following
each member briefly describes its meaning.
The member tm_isdst
contains:
See also the Table of Contents and the Index.
Copyright © 1989-1996 by P.J. Plauger and Jim Brodie. All rights reserved.