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