1*48352Scael.\" Copyright (c) 1989, 1991 The Regents of the University of California. 237192Sbostic.\" 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*48352Scael.\" @(#)ctime.3 6.15 (Berkeley) 04/19/91 937192Sbostic.\" 10*48352Scael.Dd 11*48352Scael.Dt CTIME 3 12*48352Scael.Os BSD 4.3 13*48352Scael.Sh NAME 14*48352Scael.Nm asctime , 15*48352Scael.Nm ctime , 16*48352Scael.Nm difftime , 17*48352Scael.Nm gmtime , 18*48352Scael.Nm localtime , 19*48352Scael.Nm mktime 20*48352Scael.Nd transform binary date and time value to 21*48352Scael.Tn ASCII 22*48352Scael.Sh SYNOPSIS 23*48352Scael.Fd #include <sys/types.h> 24*48352Scael.Vt extern char *tzname[2]; 25*48352Scael.Ft char * 26*48352Scael.Fn ctime "const time_t *clock" 27*48352Scael.Ft double 28*48352Scael.Fn difftime "time_t time1" "time_t time0" 29*48352Scael.Fd #include <time.h> 30*48352Scael.Ft char * 31*48352Scael.Fn asctime "const struct tm *tm" 32*48352Scael.Ft struct tm * 33*48352Scael.Fn localtime "const time_t *clock" 34*48352Scael.Ft struct tm * 35*48352Scael.Fn gmtime "const time_t *clock" 36*48352Scael.Ft time_t 37*48352Scael.Fn mktime "struct tm *tm" 38*48352Scael.Sh DESCRIPTION 39*48352ScaelThe functions 40*48352Scael.Fn ctime , 41*48352Scael.Fn gmtime 4245691Sbosticand 43*48352Scael.Fn localtime 4445691Sbosticall take as an argument a time value representing the time in seconds since 45*48352Scaelthe Epoch (00:00:00 46*48352Scael.Tn UTC , 47*48352ScaelJanuary 1, 1970; see 48*48352Scael.Xr time 3 ) . 49*48352Scael.Pp 50*48352ScaelThe function 51*48352Scael.Fn localtime 5245691Sbosticconverts the time value pointed at by 53*48352Scael.Fa clock , 54*48352Scaeland returns a pointer to a 55*48352Scael.Dq Fa struct tm 56*48352Scael(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 60*48352Scael.Ev TZ 6145691Sbosticenvironmental variable (see 62*48352Scael.Xr tzset 3 ) . 63*48352ScaelThe function 64*48352Scael.Fn localtime 6545691Sbosticuses 66*48352Scael.Xr tzset 6745691Sbosticto initialize time conversion information if 68*48352Scael.Xr tzset 6945691Sbostichas not already been called by the process. 70*48352Scael.Pp 7145691SbosticAfter filling in the tm structure, 72*48352Scael.Fn localtime 7337192Sbosticsets the 74*48352Scael.Fa tm_isdst Ns 'th 7537192Sbosticelement of 76*48352Scael.Fa tzname 77*48352Scaelto a pointer to an 78*48352Scael.Tn ASCII 79*48352Scaelstring that's the time zone abbreviation to be 8045691Sbosticused with 81*48352Scael.Fn localtime Ns 's 8237192Sbosticreturn value. 83*48352Scael.Pp 84*48352ScaelThe function 85*48352Scael.Fn gmtime 8645691Sbosticsimilarly converts the time value, but without any time zone adjustment, 8745691Sbosticand returns a pointer to a tm structure (described below). 88*48352Scael.Pp 89*48352ScaelThe 90*48352Scael.Fn ctime 91*48352Scaelfunction 9245691Sbosticadjusts the time value for the current time zone in the same manner as 93*48352Scael.Fn localtime , 9445691Sbosticand returns a pointer to a 26-character string of the form: 95*48352Scael.Bd -literal -offset indent 9645691SbosticThu Nov 24 18:22:48 1986\en\e0 97*48352Scael.Ed 98*48352Scael.Pp 9945691SbosticAll the fields have constant width. 100*48352Scael.Pp 101*48352ScaelThe 102*48352Scael.Fn asctime 103*48352Scaelfunction 104*48352Scaelconverts the broken down time in the structure 105*48352Scael.Fa tm 106*48352Scaelpointed at by 107*48352Scael.Fa *tm 108*48352Scaelto the form 109*48352Scaelshown in the example above. 110*48352Scael.Pp 111*48352ScaelThe function 112*48352Scael.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 116*48352Scael.Xr time 3 117*48352Scaelfunction, that is, seconds from the Epoch, 118*48352Scael.Tn UTC . 119*48352Scael.Pp 12037192SbosticThe original values of the 121*48352Scael.Fa tm_wday 12237192Sbosticand 123*48352Scael.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 127*48352Scael.Fa tm_isdst 12837192Sbosticcauses 129*48352Scael.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 133*48352Scael.Fa tm_isdst 13437192Sbosticcauses the 135*48352Scael.Fn mktime 13645691Sbosticfunction to attempt to divine whether summer time is in effect for the 13745691Sbosticspecified time.) 138*48352Scael.Pp 13937192SbosticOn successful completion, the values of the 140*48352Scael.Fa tm_wday 14137192Sbosticand 142*48352Scael.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 146*48352Scael.Fa tm_mday 14737192Sbosticis not set until 148*48352Scael.Fa tm_mon 14937192Sbosticand 150*48352Scael.Fa tm_year 15137192Sbosticare determined. 152*48352Scael.Fn Mktime 15345691Sbosticreturns the specified calendar time; if the calendar time cannot be 154*48352Scaelrepresented, it returns \-1; 155*48352Scael.Pp 156*48352ScaelThe 157*48352Scael.Fn difftime 158*48352Scaelfunction 15937192Sbosticreturns the difference between two calendar times, 160*48352Scael.Pf ( Fa time1 16137192Sbostic- 162*48352Scael.Fa time0 ) , 16337192Sbosticexpressed in seconds. 164*48352Scael.Pp 16545691SbosticExternal declarations as well as the tm structure definition are in the 166*48352Scael.Aq Pa time.h 167*48352Scaelinclude file. 16845691SbosticThe tm structure includes at least the following fields: 169*48352Scael.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 \(**/ 181*48352Scael.Ed 182*48352Scael.Pp 183*48352ScaelThe 184*48352Scaelfield 185*48352Scael.Fa tm_isdst 18637192Sbosticis non-zero if summer time is in effect. 187*48352Scael.Pp 188*48352ScaelThe field 189*48352Scael.Fa tm_gmtoff 190*48352Scaelis the offset (in seconds) of the time represented from 191*48352Scael.Tn UTC , 192*48352Scaelwith positive 19345691Sbosticvalues indicating east of the Prime Meridian. 194*48352Scael.Sh SEE ALSO 195*48352Scael.Xr date 1 , 196*48352Scael.Xr gettimeofday 2 , 197*48352Scael.Xr getenv 3 , 198*48352Scael.Xr time 3 , 199*48352Scael.Xr tzset 3 , 200*48352Scael.Xr tzfile 5 201*48352Scael.Sh HISTORY 202*48352ScaelThis manual page is derived from 203*48352Scaelthe time package contributed to Berkeley by 204*48352ScaelArthur Olsen and which appeared in 205*48352Scael.Bx 4.3 . 206*48352Scael.Sh BUGS 20745691SbosticExcept for 208*48352Scael.Fn difftime 20945691Sbosticand 210*48352Scael.Fn mktime , 211*48352Scaelthese functions leaves their result in an internal static object and return 212*48352Scaela pointer to that object. Subsequent calls to these 213*48352Scaelfunction will modify the same object. 214*48352Scael.Pp 21537192SbosticThe 216*48352Scael.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 220*48352Scael.Xr tzset 3 22145691Sbosticand 222*48352Scael.Xr tzsetwall 3 ) . 223*48352Scael.Pp 22445691SbosticUse of the external variable 225*48352Scael.Fa tzname 22645691Sbosticis discouraged; the 227*48352Scael.Fa tm_zone 22845691Sbosticentry in the tm structure is preferred. 229*48352Scael.Pp 23037192SbosticAvoid using out-of-range values with 231*48352Scael.Fn mktime 23237192Sbosticwhen setting up lunch with promptness sticklers in Riyadh. 233