说明:
strptime(),按照特定时间格式将字符串转换为时间类型。
#include <time.h>
char *strptime(const char *buf,const char *format, struct tm *tm);
参数说明:
buf | 时间字符串指针 |
format | 格式字符串指针 |
tm | 保存转换后结果的时间结构体指针 |
返回值:
调用成功返回 *buf最后位置,失败返回空指针。
例子
char fmt[] = "%Y-%m-%d-%H:%M:%S";
char buf[] = "2000-01-01-00:00:00";
struct tm tb;
if (strptime(buf, fmt, &tb) != NULL) {
fprintf(stdout "ok");
}