1.\" Copyright (c) 1980, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)gettimeofday.2 8.2 (Berkeley) 05/26/95 7.\" 8.Dd 9.Dt GETTIMEOFDAY 2 10.Os BSD 4 11.Sh NAME 12.Nm gettimeofday , 13.Nm settimeofday 14.Nd get/set date and time 15.Sh SYNOPSIS 16.Fd #include <sys/time.h> 17.Ft int 18.Fn gettimeofday "struct timeval *tp" "struct timezone *tzp" 19.Ft int 20.Fn settimeofday "struct timeval *tp" "struct timezone *tzp" 21.Sh DESCRIPTION 22.Bf -symbolic 23Note: timezone is no longer used; this information is kept outside 24the kernel. 25.Ef 26The system's notion of the current Greenwich time and the current time 27zone is obtained with the 28.Fn gettimeofday 29call, and set with the 30.Fn settimeofday 31call. The time is expressed in seconds and microseconds 32since midnight (0 hour), January 1, 1970. The resolution of the system 33clock is hardware dependent, and the time may be updated continuously or 34in ``ticks.'' If 35.Fa tp 36or 37.Fa tzp 38is NULL, the associated time 39information will not be returned or set. 40.Pp 41The structures pointed to by 42.Fa tp 43and 44.Fa tzp 45are defined in 46.Ao Pa sys/time.h Ac 47as: 48.Pp 49.Bd -literal 50struct timeval { 51 long tv_sec; /* seconds since Jan. 1, 1970 */ 52 long tv_usec; /* and microseconds */ 53}; 54 55struct timezone { 56 int tz_minuteswest; /* of Greenwich */ 57 int tz_dsttime; /* type of dst correction to apply */ 58}; 59.Ed 60.Pp 61The 62.Fa timezone 63structure indicates the local time zone 64(measured in minutes of time westward from Greenwich), 65and a flag that, if nonzero, indicates that 66Daylight Saving time applies locally during 67the appropriate part of the year. 68.Pp 69Only the super-user may set the time of day or time zone. 70If the system is running in secure mode (see 71.Xr init 8 ), 72the time may only be advanced. 73This limitation is imposed to prevent a malicious super-user 74from setting arbitrary time stamps on files. 75The system time can still be adjusted backwards using the 76.Xr adjtime 2 77system call even when the system is secure. 78.Sh RETURN 79A 0 return value indicates that the call succeeded. 80A -1 return value indicates an error occurred, and in this 81case an error code is stored into the global variable 82.Va errno . 83.Sh ERRORS 84The following error codes may be set in 85.Va errno : 86.Bl -tag -width [EFAULT] 87.It Bq Er EFAULT 88An argument address referenced invalid memory. 89.It Bq Er EPERM 90A user other than the super-user attempted to set the time. 91.El 92.Sh SEE ALSO 93.Xr date 1 , 94.Xr adjtime 2 , 95.Xr ctime 3 , 96.Xr timed 8 97.Sh HISTORY 98The 99.Nm 100function call appeared in 101.Bx 4.2 . 102