gettimeofday(2) System Calls Manual gettimeofday(2) gettimeofday, settimeofday - / C (libc, -lc) #include [[deprecated]] int gettimeofday(struct timeval *restrict tv, struct timezone *_Nullable restrict tz); [[deprecated]] int settimeofday(const struct timeval *tv, const struct timezone *_Nullable tz); glibc (. feature_test_macros(7)): settimeofday(): glibc 2.19: _DEFAULT_SOURCE glibc 2.19 : _BSD_SOURCE gettimeofday() settimeofday() , . The tv argument is a struct timeval (as specified in ): struct timeval { time_t tv_sec; /* */ suseconds_t tv_usec; /* */ }; , (. time(2)). tz struct timezone: struct timezone { int tz_minuteswest; /* */ int tz_dsttime; /* DST */ }; tv tz NULL, ( , tv NULL). The use of the timezone structure is obsolete; the tz argument should normally be specified as NULL. See VERSIONS. Linux << >> (warp clock), settimeofday(), ( ), tz NULL, tv NULL tz_minuteswest ( tz_dsttime ). , (CMOS clock) , UTC. , , . gettimeofday() and settimeofday() return 0 for success. On error, -1 is returned and errno is set to indicate the error. EFAULT tv tz . EINVAL (settimeofday()): timezone. EINVAL (settimeofday()): tv.tv_sec is negative or tv.tv_usec is outside the range [0, 999,999]. EINVAL ( Linux 4.3) (settimeofday()): CLOCK_MONOTONIC ( clock_gettime(2)). EPERM settimeofday(); Linux CAP_SYS_TIME. C gettimeofday() vdso(7). The kernel accepts NULL for both tv and tz. The timezone argument is ignored by glibc and musl, and not passed to/from the kernel. Android's bionic passes the timezone argument to/from the kernel, but Android does not update the kernel timezone based on the device timezone in Settings, so the kernel's timezone is typically UTC. . 4.3BSD, SVr4. SUSv1 and POSIX.1-2001 XSI described gettimeofday() but not settimeofday(). POSIX.1-2008 XSI marked gettimeofday() as obsolete, recommending the use of clock_gettime(2) instead. Likewise, clock_settime(2) should be used instead of settimeofday(). POSIX.1-2024 removed gettimeofday(). , struct timeval long. tz_dsttime Linux, glibc, tz_dsttime struct timezone gettimeofday() , . daylight(3) . Linux glibc tz_dsttime struct timezone settimeofday() gettimeofday(). , . tz_dsttime ( ), (Daylight Saving Time) (: ). : DST_NONE /* not on DST */ DST_USA /* USA style DST */ DST_AUST /* Australian style DST */ DST_WET /* Western European DST */ DST_MET /* Middle European DST */ DST_EET /* Eastern European DST */ DST_CAN /* Canada */ DST_GB /* Great Britain and Eire */ DST_RUM /* Romania */ DST_TUR /* Turkey */ DST_AUSTALT /* Australian style with shift in 1986 */ Of course, it turned out that the period in which Daylight Saving Time is in force cannot be given by a simple algorithm, one per country; indeed, this period is determined by unpredictable political decisions. So this method of representing timezones has been abandoned. , gettimeofday(), (, ). , clock_gettime(2). timeval , timeradd(3). date(1), adjtimex(2), clock_gettime(2), time(2), ctime(3), ftime(3), timeradd(3), capabilities(7), time(7), vdso(7), hwclock(8) () Azamat Hackimov , Dmitry Bolkhovskikh , Vladislav , Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () . Linux man-pages 6.18 8 2026 . gettimeofday(2)