1.\" Copyright (c) 1980, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)gettimeofday.2 8.2 (Berkeley) 5/26/95 33.\" $FreeBSD$ 34.\" 35.Dd May 26, 1995 36.Dt GETTIMEOFDAY 2 37.Os 38.Sh NAME 39.Nm gettimeofday , 40.Nm settimeofday 41.Nd get/set date and time 42.Sh LIBRARY 43.Lb libc 44.Sh SYNOPSIS 45.In sys/time.h 46.Ft int 47.Fn gettimeofday "struct timeval *tp" "struct timezone *tzp" 48.Ft int 49.Fn settimeofday "const struct timeval *tp" "const struct timezone *tzp" 50.Sh DESCRIPTION 51.Bf -symbolic 52Note: timezone is no longer used; this information is kept outside 53the kernel. 54.Ef 55.Pp 56The system's notion of the current Greenwich time and the current time 57zone is obtained with the 58.Fn gettimeofday 59system call, and set with the 60.Fn settimeofday 61system call. 62The time is expressed in seconds and microseconds 63since midnight (0 hour), January 1, 1970. 64The resolution of the system 65clock is hardware dependent, and the time may be updated continuously or 66in 67.Dq ticks . 68If 69.Fa tp 70or 71.Fa tzp 72is NULL, the associated time 73information will not be returned or set. 74.Pp 75The structures pointed to by 76.Fa tp 77and 78.Fa tzp 79are defined in 80.In sys/time.h 81as: 82.Pp 83.Bd -literal 84struct timeval { 85 long tv_sec; /* seconds since Jan. 1, 1970 */ 86 long tv_usec; /* and microseconds */ 87}; 88 89struct timezone { 90 int tz_minuteswest; /* minutes west of Greenwich */ 91 int tz_dsttime; /* type of dst correction */ 92}; 93.Ed 94.Pp 95The 96.Vt timezone 97structure indicates the local time zone 98(measured in minutes of time westward from Greenwich), 99and a flag that, if nonzero, indicates that 100Daylight Saving time applies locally during 101the appropriate part of the year. 102.Pp 103Only the super-user may set the time of day or time zone. 104If the system is running at securelevel >= 2 (see 105.Xr init 8 ) , 106the time may only be advanced or retarded by a maximum of one second. 107This limitation is imposed to prevent a malicious super-user 108from setting arbitrary time stamps on files. 109The system time can be adjusted backwards without restriction using the 110.Xr adjtime 2 111system call even when the system is secure. 112.Sh RETURN VALUES 113.Rv -std 114.Sh ERRORS 115The following error codes may be set in 116.Va errno : 117.Bl -tag -width Er 118.It Bq Er EFAULT 119An argument address referenced invalid memory. 120.It Bq Er EPERM 121A user other than the super-user attempted to set the time. 122.El 123.Sh SEE ALSO 124.Xr date 1 , 125.Xr adjtime 2 , 126.Xr clock_gettime 2 , 127.Xr ctime 3 , 128.Xr timeradd 3 , 129.Xr clocks 7 , 130.Xr timed 8 131.Sh HISTORY 132The 133.Fn gettimeofday 134system call appeared in 135.Bx 4.2 . 136