Commit | Line | Data |
---|---|---|
931b8415 | 1 | .\" Copyright (c) 1980, 1991 The Regents of the University of California. |
88b3ccf2 | 2 | .\" All rights reserved. |
03365d4a | 3 | .\" |
91cff1e1 | 4 | .\" %sccs.include.redist.man% |
88b3ccf2 | 5 | .\" |
931b8415 | 6 | .\" @(#)gettimeofday.2 6.11 (Berkeley) %G% |
03365d4a | 7 | .\" |
931b8415 CL |
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 | |
1347a72e | 26 | The system's notion of the current Greenwich time and the current time |
931b8415 CL |
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 | |
1347a72e KB |
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 | |
931b8415 CL |
34 | in ``ticks.'' If |
35 | .Fa tp | |
36 | or | |
37 | .Fa tzp | |
38 | is NULL, the associated time | |
1347a72e | 39 | information will not be returned or set. |
931b8415 | 40 | .Pp |
a2364113 | 41 | The structures pointed to by |
931b8415 | 42 | .Fa tp |
a2364113 | 43 | and |
931b8415 | 44 | .Fa tzp |
a2364113 | 45 | are defined in |
931b8415 | 46 | .Ao Pa sys/time.h Ac |
a2364113 | 47 | as: |
931b8415 CL |
48 | .Pp |
49 | .Bd -literal | |
a2364113 | 50 | struct timeval { |
db2c4838 | 51 | long tv_sec; /* seconds since Jan. 1, 1970 */ |
931b8415 | 52 | long tv_usec; /* and microseconds */ |
a2364113 | 53 | }; |
931b8415 | 54 | |
a2364113 | 55 | struct timezone { |
931b8415 | 56 | int tz_minuteswest; /* of Greenwich */ |
a2364113 KM |
57 | int tz_dsttime; /* type of dst correction to apply */ |
58 | }; | |
931b8415 CL |
59 | .Ed |
60 | .Pp | |
a2364113 | 61 | The |
931b8415 | 62 | .Fa timezone |
a2364113 KM |
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. | |
931b8415 | 68 | .Pp |
db2c4838 | 69 | Only the super-user may set the time of day or time zone. |
931b8415 | 70 | .Sh RETURN |
a2364113 | 71 | A 0 return value indicates that the call succeeded. |
931b8415 CL |
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 | |
a2364113 | 80 | An argument address referenced invalid memory. |
931b8415 | 81 | .It Bq Er EPERM |
a2364113 | 82 | A user other than the super-user attempted to set the time. |
931b8415 CL |
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 . |