.\" Copyright (c) 1989 The Regents of the University of California. .\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" Arthur Olson. .\" .\" %sccs.include.redist.man% .\" .\" @(#)ctime.3 6.14 (Berkeley) %G% .\" .TH CTIME 3 "" .SH NAME asctime, ctime, difftime, gmtime, localtime, mktime \- convert date and time to ASCII .SH SYNOPSIS .nf .ft B extern char *tzname[2]; #include char *ctime(time_t *clock); double difftime(time_t time1, time_t time0); #include char *asctime(struct tm *tm); struct tm *localtime(long *clock); struct tm *gmtime(long *clock); time_t mktime(struct tm *tm); .ft R .fi .SH DESCRIPTION .IR Ctime , .I gmtime and .I localtime all take as an argument a time value representing the time in seconds since the Epoch (00:00:00 UTC, January 1, 1970; see .IR time (3)). .PP .I Localtime converts the time value pointed at by .IR clock , and returns a pointer to a ``struct tm'' (described below) which contains the broken-out time information for the value after adjusting for the current time zone (and any other factors such as Daylight Saving Time). Time zone adjustments are performed as specified by the .B TZ environmental variable (see .IR tzset (3)). .I Localtime uses .I tzset to initialize time conversion information if .I tzset has not already been called by the process. .PP After filling in the tm structure, .I localtime sets the .BR tm_isdst 'th element of .B tzname to a pointer to an ASCII string that's the time zone abbreviation to be used with .IR localtime 's return value. .PP .I Gmtime similarly converts the time value, but without any time zone adjustment, and returns a pointer to a tm structure (described below). .PP .I Ctime adjusts the time value for the current time zone in the same manner as .IR localtime , and returns a pointer to a 26-character string of the form: .sp .RS Thu Nov 24 18:22:48 1986\en\e0 .RE .sp All the fields have constant width. .PP .I Asctime converts a time value contained in a tm structure to a 26-character string, as shown in the above example, and returns a pointer to the string. .PP .I Mktime converts the broken-down time, expressed as local time, in the structure pointed to by tm into a time value with the same encoding as that of the values returned by the .IR time (3) function, that is, seconds from the Epoch, UTC. .PP The original values of the .B tm_wday and .B tm_yday 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 .B tm_isdst causes .I mktime to presume initially that summer time (for example, Daylight Saving Time) is or is not in effect for the specified time, respectively. A negative value for .B tm_isdst causes the .I mktime function to attempt to divine whether summer time is in effect for the specified time.) .PP On successful completion, the values of the .B tm_wday and .B tm_yday 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 .B tm_mday is not set until .B tm_mon and .B tm_year are determined. .I Mktime returns the specified calendar time; if the calendar time cannot be represented, it returns .BR -1 . .PP .I Difftime returns the difference between two calendar times, .RI ( time1 - .IR time0 ), expressed in seconds. .PP External declarations as well as the tm structure definition are in the ``'' include file. The tm structure includes at least the following fields: .sp .RS .nf .ta .5i +\w'long tm_gmtoff;\0\0'u int tm_sec; /\(** seconds (0 - 60) \(**/ int tm_min; /\(** minutes (0 - 59) \(**/ int tm_hour; /\(** hours (0 - 23) \(**/ int tm_mday; /\(** day of month (1 - 31) \(**/ int tm_mon; /\(** month of year (0 - 11) \(**/ int tm_year; /\(** year \- 1900 \(**/ int tm_wday; /\(** day of week (Sunday = 0) \(**/ int tm_yday; /\(** day of year (0 - 365) \(**/ int tm_isdst; /\(** is summer time in effect? \(**/ char \(**tm_zone; /\(** abbreviation of timezone name \(**/ long tm_gmtoff; /\(** offset from UTC in seconds \(**/ .fi .RE .PP .I Tm_isdst is non-zero if summer time is in effect. .PP .I Tm_gmtoff is the offset (in seconds) of the time represented from UTC, with positive values indicating east of the Prime Meridian. .SH SEE ALSO date(1), gettimeofday(2), getenv(3), time(3), tzset(3), tzfile(5) .SH BUGS Except for .I difftime and .IR mktime , these routines all return pointers to static data whose content is overwritten by each call. .PP The .B tm_zone field of a returned tm structure points to a static array of characters, which will also be overwritten by any subsequent calls (as well as by subsequent calls to .IR tzset (3) and .IR tzsetwall (3)). .PP Use of the external variable .B tzname is discouraged; the .B tm_zone entry in the tm structure is preferred. .PP Avoid using out-of-range values with .I mktime when setting up lunch with promptness sticklers in Riyadh.