time(2)
#include <time.h>
time_t time(time_t *timep);//获取当前时间距离1970-01-01 00:00:00 经历的秒数
p = struct tm *localtime(const time_t *timep);//根据上边timep的值计算出本地时间,存放在返回指针的结构体中
其中p->tm_year + 1900,p->tm_mon + 1。
--------------------------------------------------------------------------------------------------------------------------------------------------
strptime
#define _XOPEN_SOURCE /* See feature_test_macros(7) */
#include <time.h>
char *strptime(const char *s, const char *format, struct tm *tm);/0./把指定时间s按照format的格式解析到tm中。mktime(3)函数
time_t mktime(struct tm *tm);//mktime(3)根据tm可以换算出时间s距离1970-01-01 00:00:00 经历的秒数
编译的时候出现错误: warning: implicit declaration of function ‘strptime’; did you mean ‘strftime’? [-Wimplicit-function-declaration]
解决办法:编译的时候加上-D _XOPEN_SOURCE
-------------------------------------------------------------------------------------------------------------------------------------------------
strftime