Linux时间系统调用总结

来源:互联网 发布:数据集成平台的作用 编辑:程序博客网 时间:2024/05/02 00:45
#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表示的当前时间,一般用来替换gettimeofdayint 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);

0 0
原创粉丝点击