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