2003-04-16 17:34:34 +04:00
|
|
|
.\" $NetBSD: ctime.3,v 1.27 2003/04/16 13:34:58 wiz Exp $
|
2001-04-03 01:26:21 +04:00
|
|
|
.Dd March 31, 2001
|
|
|
|
.Dt CTIME 3
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm asctime ,
|
|
|
|
.Nm asctime_r ,
|
|
|
|
.Nm ctime ,
|
|
|
|
.Nm ctime_r ,
|
|
|
|
.Nm difftime ,
|
|
|
|
.Nm gmtime ,
|
|
|
|
.Nm gmtime_r ,
|
|
|
|
.Nm localtime ,
|
|
|
|
.Nm localtime_r ,
|
|
|
|
.Nm mktime
|
|
|
|
.Nd convert date and time to ASCII
|
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libc
|
|
|
|
.Sh SYNOPSIS
|
2003-04-16 17:34:34 +04:00
|
|
|
.In time.h
|
2001-04-03 01:26:21 +04:00
|
|
|
.Dv extern char *tzname[2];
|
|
|
|
.Ft char *
|
|
|
|
.Fn ctime "const time_t *clock"
|
|
|
|
.Ft char *
|
|
|
|
.Fn ctime_r "const time_t *clock" "char *buf"
|
|
|
|
.Ft double
|
|
|
|
.Fn difftime "time_t time1" "time_t time0"
|
|
|
|
.Ft char *
|
|
|
|
.Fn asctime "const struct tm *tm"
|
|
|
|
.Ft char *
|
|
|
|
.Fn asctime_r "const struct tm restrict tm" "char * restrict buf"
|
|
|
|
.Ft struct tm *
|
|
|
|
.Fn localtime "const time_t *clock"
|
|
|
|
.Ft struct tm *
|
|
|
|
.Fn localtime_r "const time_t * restrict clock" "struct tm * restrict result"
|
|
|
|
.Ft struct tm *
|
|
|
|
.Fn gmtime "const time_t *clock"
|
|
|
|
.Ft struct tm *
|
|
|
|
.Fn gmtime_r "const time_t * restrict clock" "struct tm * restrict result"
|
|
|
|
.Ft time_t
|
|
|
|
.Fn mktime "struct tm *tm"
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
.Fn ctime
|
1995-03-10 02:46:58 +03:00
|
|
|
converts a long integer, pointed to by
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa clock ,
|
|
|
|
representing the time in seconds since 00:00:00 UTC, 1970-01-01,
|
|
|
|
and returns a pointer to a 26-character string of the form
|
|
|
|
.Dl Thu Nov 24 18:22:48 1986\en\e0
|
1995-03-10 02:46:58 +03:00
|
|
|
All the fields have constant width.
|
2001-04-03 01:26:21 +04:00
|
|
|
.Pp
|
1999-05-04 19:34:50 +04:00
|
|
|
The
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn ctime_r
|
1999-05-04 19:34:50 +04:00
|
|
|
function provides the same functionality as
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn ctime
|
1999-05-04 19:34:50 +04:00
|
|
|
differing in that the caller must supply a buffer area
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa buf
|
1999-05-04 19:34:50 +04:00
|
|
|
with a size of at least 26 bytes, in which the result is stored.
|
2001-04-03 01:26:21 +04:00
|
|
|
.Pp
|
|
|
|
.Fn localtime
|
1995-03-10 02:46:58 +03:00
|
|
|
and
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn gmtime
|
|
|
|
return pointers to
|
|
|
|
.Va tm
|
|
|
|
structures, described below.
|
|
|
|
.Fn localtime
|
1995-03-10 02:46:58 +03:00
|
|
|
corrects for the time zone and any time zone adjustments
|
|
|
|
(such as Daylight Saving Time in the U.S.A.).
|
2001-04-03 01:26:21 +04:00
|
|
|
After filling in the
|
|
|
|
.Va tm
|
|
|
|
structure,
|
|
|
|
.Fn localtime
|
1995-03-10 02:46:58 +03:00
|
|
|
sets the
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa tm_isdst Ns 'th
|
1995-03-10 02:46:58 +03:00
|
|
|
element of
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa tzname
|
1995-03-10 02:46:58 +03:00
|
|
|
to a pointer to an
|
|
|
|
ASCII string that's the time zone abbreviation to be used with
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn localtime Ns 's
|
1995-03-10 02:46:58 +03:00
|
|
|
return value.
|
2001-04-03 01:26:21 +04:00
|
|
|
.Pp
|
|
|
|
.Fn gmtime
|
1995-03-10 02:46:58 +03:00
|
|
|
converts to Coordinated Universal Time.
|
2001-04-03 01:26:21 +04:00
|
|
|
.Pp
|
1999-05-04 19:34:50 +04:00
|
|
|
The
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn gmtime_r
|
1999-05-04 19:34:50 +04:00
|
|
|
and
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn localtime_r
|
1999-05-04 19:34:50 +04:00
|
|
|
functions provide the same functionality as
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn gmtime
|
1999-05-04 19:34:50 +04:00
|
|
|
and
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn localtime
|
1999-05-04 19:34:50 +04:00
|
|
|
differing in that the caller must supply a buffer area
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa result
|
2000-07-06 20:19:15 +04:00
|
|
|
in which the result is stored; also,
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn localtime_r
|
2000-07-06 20:19:15 +04:00
|
|
|
does not imply initialization of the local time conversion information;
|
|
|
|
the application may need to do so by calling
|
2001-04-03 01:26:21 +04:00
|
|
|
.Xr tzset 3 .
|
|
|
|
.Pp
|
|
|
|
.Fn asctime
|
1995-03-10 02:46:58 +03:00
|
|
|
converts a time value contained in a
|
2001-04-03 01:26:21 +04:00
|
|
|
.Va tm
|
|
|
|
structure to a 26-character string, as shown in the above example,
|
|
|
|
and returns a pointer to the string.
|
|
|
|
.Pp
|
1999-05-04 19:34:50 +04:00
|
|
|
The
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn asctime_r
|
1999-05-04 19:34:50 +04:00
|
|
|
function provides the same functionality as
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn asctime
|
1999-05-04 19:34:50 +04:00
|
|
|
differing in that the caller must supply a buffer area
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa buf
|
1999-05-04 19:34:50 +04:00
|
|
|
with a size of at least 26 bytes, in which the result is stored.
|
2001-04-03 01:26:21 +04:00
|
|
|
.Pp
|
|
|
|
.Fn mktime
|
|
|
|
converts the broken-down time, expressed as local time,
|
1995-03-10 02:46:58 +03:00
|
|
|
in the structure pointed to by
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa tm
|
1995-03-10 02:46:58 +03:00
|
|
|
into a calendar time value with the same encoding as that of the values
|
|
|
|
returned by the
|
2001-04-03 01:26:21 +04:00
|
|
|
.Xr time 3
|
1995-03-10 02:46:58 +03:00
|
|
|
function.
|
|
|
|
The original values of the
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa tm_wday
|
1995-03-10 02:46:58 +03:00
|
|
|
and
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa tm_yday
|
1995-03-10 02:46:58 +03:00
|
|
|
components of the structure are ignored,
|
|
|
|
and the original values of the other components are not restricted
|
|
|
|
to their normal ranges.
|
|
|
|
(A positive or zero value for
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa tm_isdst
|
1995-03-10 02:46:58 +03:00
|
|
|
causes
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn mktime
|
1995-03-10 02:46:58 +03:00
|
|
|
to presume initially that summer time (for example, Daylight Saving Time
|
2001-04-03 01:26:21 +04:00
|
|
|
in the U.S.A.) respectively,
|
2002-10-01 22:15:59 +04:00
|
|
|
is or is not in effect for the specified time.
|
|
|
|
A negative value for
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa tm_isdst
|
1995-03-10 02:46:58 +03:00
|
|
|
causes the
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn mktime
|
1995-03-10 02:46:58 +03:00
|
|
|
function to attempt to divine whether summer time is in effect
|
|
|
|
for the specified time.)
|
|
|
|
On successful completion, the values of the
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa tm_wday
|
1995-03-10 02:46:58 +03:00
|
|
|
and
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa tm_yday
|
1995-03-10 02:46:58 +03:00
|
|
|
components of the structure are set appropriately,
|
|
|
|
and the other components are set to represent the specified calendar time,
|
|
|
|
but with their values forced to their normal ranges; the final value of
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa tm_mday
|
1995-03-10 02:46:58 +03:00
|
|
|
is not set until
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa tm_mon
|
1995-03-10 02:46:58 +03:00
|
|
|
and
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa tm_year
|
1995-03-10 02:46:58 +03:00
|
|
|
are determined.
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn mktime
|
|
|
|
returns the specified calendar time; if the calendar time cannot be
|
|
|
|
represented, it returns -1.
|
|
|
|
.Pp
|
|
|
|
.Fn difftime
|
1995-03-10 02:46:58 +03:00
|
|
|
returns the difference between two calendar times,
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa ( time1 No - Fa time0 ) ,
|
1995-03-10 02:46:58 +03:00
|
|
|
expressed in seconds.
|
2001-04-03 01:26:21 +04:00
|
|
|
.Pp
|
1995-03-10 02:46:58 +03:00
|
|
|
The structure (of type)
|
2001-04-03 01:26:21 +04:00
|
|
|
.Va "struct tm"
|
1995-03-10 02:46:58 +03:00
|
|
|
includes the following fields:
|
2001-04-03 01:26:21 +04:00
|
|
|
.Bd -literal -offset indent
|
|
|
|
int tm_sec; /* seconds after the minute [0,61] */
|
|
|
|
int tm_min; /* minutes after the hour [0,59] */
|
|
|
|
int tm_hour; /* hours since midnight [0,23] */
|
|
|
|
int tm_mday; /* day of the month [1,31] */
|
|
|
|
int tm_mon; /* months since January [0,11] */
|
|
|
|
int tm_year; /* years since 1900 */
|
|
|
|
int tm_wday; /* day of week [0,6] (Sunday = 0) */
|
|
|
|
int tm_yday; /* day of year [0,365] (Jan 1 = 0) */
|
|
|
|
int tm_isdst; /* daylight savings flag */
|
|
|
|
long tm_gmtoff; /* offset from UTC in seconds */
|
|
|
|
char *tm_zone; /* abbreviation of timezone name */
|
|
|
|
.Ed
|
|
|
|
.Pp
|
1995-03-10 02:46:58 +03:00
|
|
|
The
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa tm_zone
|
1995-03-10 02:46:58 +03:00
|
|
|
and
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa tm_gmtoff
|
1995-03-10 02:46:58 +03:00
|
|
|
fields exist, and are filled in, only if arrangements to do
|
|
|
|
so were made when the library containing these functions was
|
|
|
|
created.
|
|
|
|
There is no guarantee that these fields will continue to exist
|
|
|
|
in this form in future releases of this code.
|
2001-04-03 01:26:21 +04:00
|
|
|
.Pp
|
|
|
|
.Fa tm_isdst
|
1995-03-10 02:46:58 +03:00
|
|
|
is non-zero if summer time is in effect.
|
2001-04-03 01:26:21 +04:00
|
|
|
.Pp
|
|
|
|
.Fa tm_gmtoff
|
1995-03-10 02:46:58 +03:00
|
|
|
is the offset (in seconds) of the time represented
|
|
|
|
from UTC, with positive values indicating east
|
|
|
|
of the Prime Meridian.
|
2001-04-03 01:26:21 +04:00
|
|
|
.Sh FILES
|
|
|
|
.Bl -tag -width /usr/share/zoneinfo/posixrules -compact
|
|
|
|
.It Pa /etc/localtime
|
|
|
|
local time zone file
|
|
|
|
.It Pa /usr/share/zoneinfo
|
|
|
|
time zone information directory
|
|
|
|
.It Pa /usr/share/zoneinfo/posixrules
|
|
|
|
used with POSIX-style TZ's
|
|
|
|
.It Pa /usr/share/zoneinfo/GMT
|
|
|
|
for UTC leap seconds
|
|
|
|
.El
|
|
|
|
.Pp
|
1995-03-10 02:46:58 +03:00
|
|
|
If
|
2001-04-03 01:26:21 +04:00
|
|
|
.Pa /usr/share/zoneinfo/GMT
|
|
|
|
is absent, UTC leap seconds are loaded from
|
|
|
|
.Pa /usr/share/zoneinfo/posixrules .
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr getenv 3 ,
|
|
|
|
.Xr strftime 3 ,
|
|
|
|
.Xr time 3 ,
|
2001-09-16 05:35:53 +04:00
|
|
|
.Xr tzset 3 ,
|
2001-04-03 01:26:21 +04:00
|
|
|
.Xr tzfile 5
|
|
|
|
.Sh STANDARDS
|
1997-07-15 03:35:02 +04:00
|
|
|
The
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn ctime ,
|
|
|
|
.Fn difftime ,
|
|
|
|
.Fn asctime ,
|
|
|
|
.Fn localtime ,
|
|
|
|
.Fn gmtime
|
1997-07-15 03:35:02 +04:00
|
|
|
and
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn mktime
|
1997-07-15 03:35:02 +04:00
|
|
|
functions conform to
|
2001-04-03 01:26:21 +04:00
|
|
|
.St -ansiC
|
1997-07-15 03:35:02 +04:00
|
|
|
The
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn ctime_r ,
|
|
|
|
.Fn asctime_r ,
|
|
|
|
.Fn localtime_r
|
1999-05-04 19:34:50 +04:00
|
|
|
and
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn gmtime_r
|
1999-05-04 19:34:50 +04:00
|
|
|
functions conform to
|
2001-04-03 01:26:21 +04:00
|
|
|
.St -p1003.1c-95 .
|
|
|
|
.Sh NOTES
|
|
|
|
The return values point to static data; the data is overwritten by
|
2002-10-01 22:15:59 +04:00
|
|
|
each call.
|
|
|
|
The
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fa tm_zone
|
1995-03-10 02:46:58 +03:00
|
|
|
field of a returned
|
2001-04-03 01:26:21 +04:00
|
|
|
.Va "struct tm"
|
|
|
|
points to a static array of characters, which will also be overwritten
|
|
|
|
at the next call (and by calls to
|
|
|
|
.Xr tzset 3 ) .
|
|
|
|
.Pp
|
1995-03-10 02:46:58 +03:00
|
|
|
Avoid using out-of-range values with
|
2001-04-03 01:26:21 +04:00
|
|
|
.Fn mktime
|
1995-03-10 02:46:58 +03:00
|
|
|
when setting up lunch with promptness sticklers in Riyadh.
|
2001-04-03 01:26:21 +04:00
|
|
|
.\" @(#)newctime.3 7.14
|