1*47208Scael.\" Copyright (c) 1980, 1991 The Regents of the University of California. 238053Sbostic.\" All rights reserved. 320138Smckusick.\" 443568Strent.\" %sccs.include.redist.man% 520138Smckusick.\" 6*47208Scael.\" @(#)gettimeofday.2 6.11 (Berkeley) 03/10/91 738053Sbostic.\" 8*47208Scael.Dd 9*47208Scael.Dt GETTIMEOFDAY 2 10*47208Scael.Os BSD 4 11*47208Scael.Sh NAME 12*47208Scael.Nm gettimeofday , 13*47208Scael.Nm settimeofday 14*47208Scael.Nd get/set date and time 15*47208Scael.Sh SYNOPSIS 16*47208Scael.Fd #include <sys/time.h> 17*47208Scael.Ft int 18*47208Scael.Fn gettimeofday "struct timeval *tp" "struct timezone *tzp" 19*47208Scael.Ft int 20*47208Scael.Fn settimeofday "struct timeval *tp" "struct timezone *tzp" 21*47208Scael.Sh DESCRIPTION 22*47208Scael.Bf -symbolic 23*47208ScaelNote: timezone is no longer used; this information is kept outside 24*47208Scaelthe kernel. 25*47208Scael.Ef 2630889SbosticThe system's notion of the current Greenwich time and the current time 27*47208Scaelzone is obtained with the 28*47208Scael.Fn gettimeofday 29*47208Scaelcall, and set with the 30*47208Scael.Fn settimeofday 31*47208Scaelcall. The time is expressed in seconds and microseconds 3230889Sbosticsince midnight (0 hour), January 1, 1970. The resolution of the system 3330889Sbosticclock is hardware dependent, and the time may be updated continuously or 34*47208Scaelin ``ticks.'' If 35*47208Scael.Fa tp 36*47208Scaelor 37*47208Scael.Fa tzp 38*47208Scaelis NULL, the associated time 3930889Sbosticinformation will not be returned or set. 40*47208Scael.Pp 4120139SmckusickThe structures pointed to by 42*47208Scael.Fa tp 4320139Smckusickand 44*47208Scael.Fa tzp 4520139Smckusickare defined in 46*47208Scael.Ao Pa sys/time.h Ac 4720139Smckusickas: 48*47208Scael.Pp 49*47208Scael.Bd -literal 5020139Smckusickstruct timeval { 5127648Slepreau long tv_sec; /* seconds since Jan. 1, 1970 */ 52*47208Scael long tv_usec; /* and microseconds */ 5320139Smckusick}; 54*47208Scael 5520139Smckusickstruct timezone { 56*47208Scael int tz_minuteswest; /* of Greenwich */ 5720139Smckusick int tz_dsttime; /* type of dst correction to apply */ 5820139Smckusick}; 59*47208Scael.Ed 60*47208Scael.Pp 6120139SmckusickThe 62*47208Scael.Fa timezone 6320139Smckusickstructure indicates the local time zone 6420139Smckusick(measured in minutes of time westward from Greenwich), 6520139Smckusickand a flag that, if nonzero, indicates that 6620139SmckusickDaylight Saving time applies locally during 6720139Smckusickthe appropriate part of the year. 68*47208Scael.Pp 6927648SlepreauOnly the super-user may set the time of day or time zone. 70*47208Scael.Sh RETURN 7120139SmckusickA 0 return value indicates that the call succeeded. 72*47208ScaelA -1 return value indicates an error occurred, and in this 73*47208Scaelcase an error code is stored into the global variable 74*47208Scael.Va errno . 75*47208Scael.Sh ERRORS 76*47208ScaelThe following error codes may be set in 77*47208Scael.Va errno : 78*47208Scael.Bl -tag -width [EFAULT] 79*47208Scael.It Bq Er EFAULT 8020139SmckusickAn argument address referenced invalid memory. 81*47208Scael.It Bq Er EPERM 8220139SmckusickA user other than the super-user attempted to set the time. 83*47208Scael.El 84*47208Scael.Sh SEE ALSO 85*47208Scael.Xr date 1 , 86*47208Scael.Xr adjtime 2 , 87*47208Scael.Xr ctime 3 , 88*47208Scael.Xr timed 8 89*47208Scael.Sh HISTORY 90*47208ScaelThe 91*47208Scael.Nm 92*47208Scaelfunction call appeared in 93*47208Scael.Bx 4.2 . 94