1*61111Sbostic.\" Copyright (c) 1989, 1991, 1993 2*61111Sbostic.\" The Regents of the University of California. All rights reserved. 320412Smckusick.\" 437192Sbostic.\" This code is derived from software contributed to Berkeley by 537192Sbostic.\" Arthur Olson. 643571Strent.\" %sccs.include.redist.man% 737192Sbostic.\" 8*61111Sbostic.\" @(#)ctime.3 8.1 (Berkeley) 06/04/93 937192Sbostic.\" 1048352Scael.Dd 1148352Scael.Dt CTIME 3 1248352Scael.Os BSD 4.3 1348352Scael.Sh NAME 1448352Scael.Nm asctime , 1548352Scael.Nm ctime , 1648352Scael.Nm difftime , 1748352Scael.Nm gmtime , 1848352Scael.Nm localtime , 1948352Scael.Nm mktime 2048352Scael.Nd transform binary date and time value to 2148352Scael.Tn ASCII 2248352Scael.Sh SYNOPSIS 2348352Scael.Fd #include <sys/types.h> 2453067Sbostic.Fd #include <time.h> 2548352Scael.Vt extern char *tzname[2]; 2648352Scael.Ft char * 2748352Scael.Fn ctime "const time_t *clock" 2848352Scael.Ft double 2948352Scael.Fn difftime "time_t time1" "time_t time0" 3048352Scael.Ft char * 3148352Scael.Fn asctime "const struct tm *tm" 3248352Scael.Ft struct tm * 3348352Scael.Fn localtime "const time_t *clock" 3448352Scael.Ft struct tm * 3548352Scael.Fn gmtime "const time_t *clock" 3648352Scael.Ft time_t 3748352Scael.Fn mktime "struct tm *tm" 3848352Scael.Sh DESCRIPTION 3948352ScaelThe functions 4048352Scael.Fn ctime , 4148352Scael.Fn gmtime 4245691Sbosticand 4348352Scael.Fn localtime 4445691Sbosticall take as an argument a time value representing the time in seconds since 4548352Scaelthe Epoch (00:00:00 4648352Scael.Tn UTC , 4748352ScaelJanuary 1, 1970; see 4848352Scael.Xr time 3 ) . 4948352Scael.Pp 5048352ScaelThe function 5148352Scael.Fn localtime 5245691Sbosticconverts the time value pointed at by 5348352Scael.Fa clock , 5448352Scaeland returns a pointer to a 5548352Scael.Dq Fa struct tm 5648352Scael(described below) which contains 5745691Sbosticthe broken-out time information for the value after adjusting for the current 5845691Sbostictime zone (and any other factors such as Daylight Saving Time). 5945691SbosticTime zone adjustments are performed as specified by the 6048352Scael.Ev TZ 6145691Sbosticenvironmental variable (see 6248352Scael.Xr tzset 3 ) . 6348352ScaelThe function 6448352Scael.Fn localtime 6545691Sbosticuses 6648352Scael.Xr tzset 6745691Sbosticto initialize time conversion information if 6848352Scael.Xr tzset 6945691Sbostichas not already been called by the process. 7048352Scael.Pp 7145691SbosticAfter filling in the tm structure, 7248352Scael.Fn localtime 7337192Sbosticsets the 7448352Scael.Fa tm_isdst Ns 'th 7537192Sbosticelement of 7648352Scael.Fa tzname 7748352Scaelto a pointer to an 7848352Scael.Tn ASCII 7948352Scaelstring that's the time zone abbreviation to be 8045691Sbosticused with 8148352Scael.Fn localtime Ns 's 8237192Sbosticreturn value. 8348352Scael.Pp 8448352ScaelThe function 8548352Scael.Fn gmtime 8645691Sbosticsimilarly converts the time value, but without any time zone adjustment, 8745691Sbosticand returns a pointer to a tm structure (described below). 8848352Scael.Pp 8948352ScaelThe 9048352Scael.Fn ctime 9148352Scaelfunction 9245691Sbosticadjusts the time value for the current time zone in the same manner as 9348352Scael.Fn localtime , 9445691Sbosticand returns a pointer to a 26-character string of the form: 9548352Scael.Bd -literal -offset indent 9645691SbosticThu Nov 24 18:22:48 1986\en\e0 9748352Scael.Ed 9848352Scael.Pp 9945691SbosticAll the fields have constant width. 10048352Scael.Pp 10148352ScaelThe 10248352Scael.Fn asctime 10348352Scaelfunction 10448352Scaelconverts the broken down time in the structure 10548352Scael.Fa tm 10648352Scaelpointed at by 10748352Scael.Fa *tm 10848352Scaelto the form 10948352Scaelshown in the example above. 11048352Scael.Pp 11148352ScaelThe function 11248352Scael.Fn mktime 11345691Sbosticconverts the broken-down time, expressed as local time, in the structure 11445691Sbosticpointed to by tm into a time value with the same encoding as that of the 11545691Sbosticvalues returned by the 11648352Scael.Xr time 3 11748352Scaelfunction, that is, seconds from the Epoch, 11848352Scael.Tn UTC . 11948352Scael.Pp 12037192SbosticThe original values of the 12148352Scael.Fa tm_wday 12237192Sbosticand 12348352Scael.Fa tm_yday 12445691Sbosticcomponents of the structure are ignored, and the original values of the 12545691Sbosticother components are not restricted to their normal ranges. 12637192Sbostic(A positive or zero value for 12748352Scael.Fa tm_isdst 12837192Sbosticcauses 12948352Scael.Fn mktime 13045691Sbosticto presume initially that summer time (for example, Daylight Saving Time) 13145691Sbosticis or is not in effect for the specified time, respectively. 13237192SbosticA negative value for 13348352Scael.Fa tm_isdst 13437192Sbosticcauses the 13548352Scael.Fn mktime 13645691Sbosticfunction to attempt to divine whether summer time is in effect for the 13745691Sbosticspecified time.) 13848352Scael.Pp 13937192SbosticOn successful completion, the values of the 14048352Scael.Fa tm_wday 14137192Sbosticand 14248352Scael.Fa tm_yday 14345691Sbosticcomponents of the structure are set appropriately, and the other components 14445691Sbosticare set to represent the specified calendar time, but with their values 14545691Sbosticforced to their normal ranges; the final value of 14648352Scael.Fa tm_mday 14737192Sbosticis not set until 14848352Scael.Fa tm_mon 14937192Sbosticand 15048352Scael.Fa tm_year 15137192Sbosticare determined. 15248352Scael.Fn Mktime 15345691Sbosticreturns the specified calendar time; if the calendar time cannot be 15448352Scaelrepresented, it returns \-1; 15548352Scael.Pp 15648352ScaelThe 15748352Scael.Fn difftime 15848352Scaelfunction 15937192Sbosticreturns the difference between two calendar times, 16048352Scael.Pf ( Fa time1 16137192Sbostic- 16248352Scael.Fa time0 ) , 16337192Sbosticexpressed in seconds. 16448352Scael.Pp 16545691SbosticExternal declarations as well as the tm structure definition are in the 16648352Scael.Aq Pa time.h 16748352Scaelinclude file. 16845691SbosticThe tm structure includes at least the following fields: 16948352Scael.Bd -literal -offset indent 17045691Sbosticint tm_sec; /\(** seconds (0 - 60) \(**/ 17145691Sbosticint tm_min; /\(** minutes (0 - 59) \(**/ 17245691Sbosticint tm_hour; /\(** hours (0 - 23) \(**/ 17345691Sbosticint tm_mday; /\(** day of month (1 - 31) \(**/ 17445691Sbosticint tm_mon; /\(** month of year (0 - 11) \(**/ 17545691Sbosticint tm_year; /\(** year \- 1900 \(**/ 17645691Sbosticint tm_wday; /\(** day of week (Sunday = 0) \(**/ 17745691Sbosticint tm_yday; /\(** day of year (0 - 365) \(**/ 17845691Sbosticint tm_isdst; /\(** is summer time in effect? \(**/ 17945691Sbosticchar \(**tm_zone; /\(** abbreviation of timezone name \(**/ 18045691Sbosticlong tm_gmtoff; /\(** offset from UTC in seconds \(**/ 18148352Scael.Ed 18248352Scael.Pp 18348352ScaelThe 18448352Scaelfield 18548352Scael.Fa tm_isdst 18637192Sbosticis non-zero if summer time is in effect. 18748352Scael.Pp 18848352ScaelThe field 18948352Scael.Fa tm_gmtoff 19048352Scaelis the offset (in seconds) of the time represented from 19148352Scael.Tn UTC , 19248352Scaelwith positive 19345691Sbosticvalues indicating east of the Prime Meridian. 19448352Scael.Sh SEE ALSO 19548352Scael.Xr date 1 , 19648352Scael.Xr gettimeofday 2 , 19748352Scael.Xr getenv 3 , 19848352Scael.Xr time 3 , 19948352Scael.Xr tzset 3 , 20048352Scael.Xr tzfile 5 20148352Scael.Sh HISTORY 20248352ScaelThis manual page is derived from 20348352Scaelthe time package contributed to Berkeley by 20448352ScaelArthur Olsen and which appeared in 20548352Scael.Bx 4.3 . 20648352Scael.Sh BUGS 20745691SbosticExcept for 20848352Scael.Fn difftime 20945691Sbosticand 21048352Scael.Fn mktime , 21148352Scaelthese functions leaves their result in an internal static object and return 21248352Scaela pointer to that object. Subsequent calls to these 21348352Scaelfunction will modify the same object. 21448352Scael.Pp 21537192SbosticThe 21648352Scael.Fa tm_zone 21745691Sbosticfield of a returned tm structure points to a static array of characters, 21845691Sbosticwhich will also be overwritten by any subsequent calls (as well as by 21945691Sbosticsubsequent calls to 22048352Scael.Xr tzset 3 22145691Sbosticand 22248352Scael.Xr tzsetwall 3 ) . 22348352Scael.Pp 22445691SbosticUse of the external variable 22548352Scael.Fa tzname 22645691Sbosticis discouraged; the 22748352Scael.Fa tm_zone 22845691Sbosticentry in the tm structure is preferred. 22948352Scael.Pp 23037192SbosticAvoid using out-of-range values with 23148352Scael.Fn mktime 23237192Sbosticwhen setting up lunch with promptness sticklers in Riyadh. 233