1.\" Copyright (c) 1980, 1991 The Regents of the University of California. 2.\" 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 6.11 (Berkeley) 3/10/91 33.\" 34.Dd March 10, 1991 35.Dt GETTIMEOFDAY 2 36.Os BSD 4 37.Sh NAME 38.Nm gettimeofday , 39.Nm settimeofday 40.Nd get/set date and time 41.Sh SYNOPSIS 42.Fd #include <sys/time.h> 43.Ft int 44.Fn gettimeofday "struct timeval *tp" "struct timezone *tzp" 45.Ft int 46.Fn settimeofday "struct timeval *tp" "struct timezone *tzp" 47.Sh DESCRIPTION 48.Bf -symbolic 49Note: timezone is no longer used; this information is kept outside 50the kernel. 51.Ef 52The system's notion of the current Greenwich time and the current time 53zone is obtained with the 54.Fn gettimeofday 55call, and set with the 56.Fn settimeofday 57call. The time is expressed in seconds and microseconds 58since midnight (0 hour), January 1, 1970. The resolution of the system 59clock is hardware dependent, and the time may be updated continuously or 60in ``ticks.'' If 61.Fa tp 62or 63.Fa tzp 64is NULL, the associated time 65information will not be returned or set. 66.Pp 67The structures pointed to by 68.Fa tp 69and 70.Fa tzp 71are defined in 72.Ao Pa sys/time.h Ac 73as: 74.Pp 75.Bd -literal 76struct timeval { 77 long tv_sec; /* seconds since Jan. 1, 1970 */ 78 long tv_usec; /* and microseconds */ 79}; 80 81struct timezone { 82 int tz_minuteswest; /* of Greenwich */ 83 int tz_dsttime; /* type of dst correction to apply */ 84}; 85.Ed 86.Pp 87The 88.Fa timezone 89structure indicates the local time zone 90(measured in minutes of time westward from Greenwich), 91and a flag that, if nonzero, indicates that 92Daylight Saving time applies locally during 93the appropriate part of the year. 94.Pp 95Only the super-user may set the time of day or time zone. 96.Sh RETURN 97A 0 return value indicates that the call succeeded. 98A -1 return value indicates an error occurred, and in this 99case an error code is stored into the global variable 100.Va errno . 101.Sh ERRORS 102The following error codes may be set in 103.Va errno : 104.Bl -tag -width [EFAULT] 105.It Bq Er EFAULT 106An argument address referenced invalid memory. 107.It Bq Er EPERM 108A user other than the super-user attempted to set the time. 109.El 110.Sh SEE ALSO 111.Xr date 1 , 112.Xr adjtime 2 , 113.Xr ctime 3 , 114.Xr timed 8 115.Sh HISTORY 116The 117.Nm 118function call appeared in 119.Bx 4.2 . 120