#include <time.h>
time.h
structtm
| int | tm_sec | seconds after the minute [0-60] |
| int | tm_min | minutes after the hour [0-59] |
| int | tm_hour | hours since midnight [0-23] |
| int | tm_mday | day of the month [1-31] |
| int | tm_mon | months since January [0-11] |
| int | tm_year | years since 1900 |
| int | tm_wday | days since Sunday [0-6] |
| int | tm_yday | days since January 1 [0-365] |
| int | tm_isdst | Daylight Savings Time flag |
| long | tm_gmtoff | offset from UTC in seconds |
| char * | tm_zone | timezone abbreviation |
variabletzname
extern char *_LIBC_CSTR tzname[_LIBC_COUNT(2)]
variablegetdate_err
extern int getdate_err
variabletimezone
extern long timezone
variabledaylight
extern int daylight
functionasctime
char *_LIBC_CSTR asctime(const struct tm *)
man page · January 2, 1999
asctime(3) — transform binary date and time valuesfunctionclock
__DARWIN_ALIAS(clock) clock_t clock(void)
man page · June 4, 1993
clock(3) — determine processor time usedfunctionctime
char *_LIBC_CSTR ctime(const time_t *)
man page · January 2, 1999
ctime(3) — transform binary date and time valuesfunctiondifftime
double difftime(time_t, time_t)
man page · January 2, 1999
difftime(3) — transform binary date and time valuesfunctiongetdate
struct tm *getdate(const char *)
man page · January 3, 2004
getdate(3) — convert user format date and timefunctiongmtime
struct tm *gmtime(const time_t *)
man page · January 2, 1999
gmtime(3) — transform binary date and time valuesfunctionlocaltime
struct tm *localtime(const time_t *)
man page · January 2, 1999
localtime(3) — transform binary date and time valuesfunctionmktime
__DARWIN_ALIAS(mktime) time_t mktime(struct tm *)
man page · January 2, 1999
mktime(3) — transform binary date and time valuesfunctionstrftime
__DARWIN_ALIAS(strftime) size_t strftime( char *_LIBC_COUNT(__maxsize) __restrict, size_t __maxsize, const char * __restrict, const struct tm * __restrict )
man page · November 4, 2004
strftime(3) — format date and timefunctionstrptime
__DARWIN_ALIAS(strptime) char *_LIBC_CSTR strptime( const char * __restrict, const char * __restrict, struct tm * __restrict )
man page · October 2, 2014
strptime(3) — parse date and time stringfunctiontzset
void tzset(void)
man page · November 17, 1993
tzset(3) — initialize time conversion informationfunctionasctime_r
char *_LIBC_CSTR asctime_r( const struct tm * __restrict, char * __restrict _LIBC_COUNT(26) )
[TSF] Thread safe functions
man page · January 2, 1999
asctime_r(3) — transform binary date and time valuesfunctionctime_r
char *_LIBC_CSTR ctime_r(const time_t *, char *_LIBC_COUNT(26))
man page · January 2, 1999
ctime_r(3) — transform binary date and time valuesfunctiongmtime_r
struct tm *gmtime_r(const time_t * __restrict, struct tm * __restrict)
man page · January 2, 1999
gmtime_r(3) — transform binary date and time valuesfunctionlocaltime_r
struct tm *localtime_r(const time_t * __restrict, struct tm * __restrict)
man page · January 2, 1999
localtime_r(3) — transform binary date and time valuesfunctionposix2time
time_t posix2time(time_t)
man page · September 11, 2005
posix2time(3) — convert seconds since the Epochfunctiontzsetwall
void tzsetwall(void)
man page · November 17, 1993
tzsetwall(3) — initialize time conversion informationfunctiontime2posix
time_t time2posix(time_t)
man page · September 11, 2005
time2posix(3) — convert seconds since the Epochfunctiontimelocal
time_t timelocal(struct tm * const)
man page · January 2, 1999
timelocal(3) — transform binary date and time valuesfunctiontimegm
time_t timegm(struct tm * const)
man page · January 2, 1999
timegm(3) — transform binary date and time valuesfunctionnanosleep
__DARWIN_ALIAS_C(nanosleep) int nanosleep(const struct timespec *__rqtp, struct timespec *__rmtp)
man page · April 17, 1997
nanosleep(2) — suspend thread execution for an interval measured in nanosecondsenumclockid_t
| _CLOCK_REALTIME | 0 | |
| _CLOCK_MONOTONIC | 6 | |
| _CLOCK_MONOTONIC_RAW | 4 | |
| _CLOCK_MONOTONIC_RAW_APPROX | 5 | |
| _CLOCK_UPTIME_RAW | 8 | |
| _CLOCK_UPTIME_RAW_APPROX | 9 | |
| _CLOCK_PROCESS_CPUTIME_ID | 12 | |
| _CLOCK_THREAD_CPUTIME_ID | 16 |
typedefclockid_t
typedef enum clockid_t clockid_t;
macroCLOCK_REALTIME
#define CLOCK_REALTIME _CLOCK_REALTIME
macroCLOCK_MONOTONIC
#define CLOCK_MONOTONIC _CLOCK_MONOTONIC
macroCLOCK_MONOTONIC_RAW
#define CLOCK_MONOTONIC_RAW _CLOCK_MONOTONIC_RAW
macroCLOCK_MONOTONIC_RAW_APPROX
#define CLOCK_MONOTONIC_RAW_APPROX _CLOCK_MONOTONIC_RAW_APPROX
macroCLOCK_UPTIME_RAW
#define CLOCK_UPTIME_RAW _CLOCK_UPTIME_RAW
macroCLOCK_UPTIME_RAW_APPROX
#define CLOCK_UPTIME_RAW_APPROX _CLOCK_UPTIME_RAW_APPROX
macroCLOCK_PROCESS_CPUTIME_ID
#define CLOCK_PROCESS_CPUTIME_ID _CLOCK_PROCESS_CPUTIME_ID
macroCLOCK_THREAD_CPUTIME_ID
#define CLOCK_THREAD_CPUTIME_ID _CLOCK_THREAD_CPUTIME_ID
functionclock_getres
__CLOCK_AVAILABILITY int clock_getres(clockid_t __clock_id, struct timespec *__res)
man page · January 26, 2016
clock_getres(3) — get/set date and timefunctionclock_gettime
__CLOCK_AVAILABILITY int clock_gettime(clockid_t __clock_id, struct timespec *__tp)
man page · January 26, 2016
clock_gettime(3) — get/set date and timefunctionclock_gettime_nsec_np
__CLOCK_AVAILABILITY __uint64_t clock_gettime_nsec_np(clockid_t __clock_id)
man page · January 26, 2016
clock_gettime_nsec_np(3) — get/set date and timefunctionclock_settime
__OSX_AVAILABLE(10.12) __IOS_PROHIBITED __TVOS_PROHIBITED __WATCHOS_PROHIBITED int clock_settime(clockid_t __clock_id, const struct timespec *__tp)
man page · January 26, 2016
clock_settime(3) — get/set date and timemacroTIME_UTC
ISO/IEC 9899:201x 7.27.2.5 The timespec_get function
#define TIME_UTC 1
time elapsed since epoch
functiontimespec_get
__API_AVAILABLE(macosx(10.15), ios(13.0), tvos(13.0), watchos(6.0)) int timespec_get(struct timespec *ts, int base)
man page · August 26, 2018
timespec_get(3) — get current calendar time