#include <time.h>
typedef __time_t time_t;
//获取time_t表示的当前时间
time_t time(time_t *t);
struct timeval
{
__time_t tv_sec;//秒
__suseconds_t tv_usec;//微秒
};
//获取timeval表示的当前时间,有BUG,少用
int gettimeofday(struct timeval *tv, struct timezone *tz);
struct timespec
{
__time_t tv_sec;//秒
__syscall_slong_t tv_nsec;//纳秒
};
//获取timespec表示的当前时间,一般用来替换gettimeofday
int clock_gettime(clockid_t clk_id, struct timespec *tp);
//上面的这些时间都是距离1970-01-01 00:00:00(UTC)的时间
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 __USE_BSD
long int tm_gmtoff;
const char *tm_zone;
#else
long int __tm_gmtoff;
const char *__tm_zone;
#endif
};
//格式化输出时间的系统调用(要么是time_t要么是struct tm)
char* asctime(const struct tm *tm);
char* asctime_r(const struct tm *tm, char *buf);
char* ctime(const time_t *timep);
char* ctime_r(const time_t *timep, char *buf);
//自定义时间的格式
size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
//想要输出timeval或者timespec格式的时间,需要先将其转化为time_t格式(直接赋值秒数)
//将time_t转化为struct tm的系统调用
struct tm* localtime(const time_t *timep);
struct tm* localtime_r(const time_t *timep, struct tm* result);