1、头文件
#include<time.h>
2、获取系统时间
time_t t = time(NULL); struct tm* pTime = localtime(&t); printf("%d-%d-%d %d:%d:%d\n", pTime->tm_year+1900, pTime->tm_mon+1, pTime->tm_mday, pTime->tm_hour, pTime->tm_min, pTime->tm_sec);
3、针对localtime过期
在文件开头添加:
#define _CRT_SECURE_NO_WARNINGS
4、localtime的反函数
time_t mktime( struct tm *timeptr ); __time32_t _mktime32( struct tm *timeptr ); __time64_t _mktime64( struct tm *timeptr );