Wall time(or real time)
Process time
Monotonic time
1. Breaking Down Time
struct tm{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
#ifdef _BSD_SOURCE
long tm_gmtoff;
const char *tm_zone;
#endif
};
2. POSIX Clocks
CLOCK_REALTIME
CLOCK_MONOTONIC
CLOCK_MONOTONIC_RAW
CLOCK_PROCESS_CPUTIME_ID
CLOCK_THREAD_CPUTIME_ID
3. Time Source Resolution
#include <time.h>
int clock_getres(clockid_t clock_id, struct timespec *res);
4. Getting the Current Time of Day
#include <time.h>
time_t time(time *t);
//返回自epoch以来的秒数
5. A Better Interface
int gettimeofday(struct timeval *tv, struct timezone *tz);
6. An Advanced Interface
#include <time.h>
int clock_gettime(clockid_t clock_id, struct timespec *ts);
7. Getting the Process Time
#include <sys/time.h>
struct tms {
clock_t tms_utime;
clock_t tms_stime;
clock_t tms_cutime;
clock_t tms_cstime;
};
clock_t times(struct tms *buf);
8. Setting the Current Time of Day
#define _SVID_SOURCE
#include <time.h>
int stime(time_t *t);
9. Setting Time with Precision
#include <sys/time.h>
int settimeofday(const struct timeval *tv,
const struct timezone *tz);
10. An Advanced Interface for Setting the Time
#include <time.h>
int clock_settime(clockid_t clock_id, const struct timespec *ts);
11. Playing with Time
#include <time.h>
char *asctime(const struct tm *tm); //不是线程安全的
char *asctime_r(const struct tm *tm, char *buf); // 线程安全的
#include <time.h>
time_t mktime(struct tm *tm);
#include <time.h>
char *ctime(const time_t *timep);
char *ctime_r(const time_t *timep, char *buf);
gmtime() converts the given time_t to a tm structure,
#include <time.h>
struct tm * gmtime(const time_t *timep);
struct tm *gmtime_r(const time_t *timep, struct tm *result);
#include <time.h>
struct tm *localtime(const time_t *timep);
struct tm *localtime_r(const time_t *timep, struct tm *result);
#include <time.h>
double difftime(time_t time1, time_t time2);
12. Timers
12.1 Simple Alarm
#include <unistd.h>
unsigned int alarm(unsigned int seconds);
12.2 Interval Timers
#include <sys/time.h>
int getitimer(int which, struct itimerval *value);
int setitimer(int which, struct itimerval *value, struct itimerval *ovaule);
struct itimerval {
struct timeval it_interval;
struct timeval it_value;
};
13. Advanced Timers
timer_create()
timer_settime()
timer_delete()