需要头文件:
#include
int GetFullSystemDateTime(char *datetime) ----获取十四位的时间
{
time_t tmptime;
struct tm *tmptm;
int tmpyear;
time(&tmptime);
tmptm = (struct tm *)localtime(&tmptime);
if(tmptm->tm_year > 90)
tmpyear = 1900 + tmptm->tm_year%1900;
else
tmpyear = 2000 + tmptm->tm_year;
sprintf(datetime,"%04d%02d%02d%02d%02d%02d",tmpyear,tmptm->tm_mon+1,tmptm->tm_mday,tmptm->tm_hour,tmptm->tm_min,tmptm->tm_sec);
return(0);
}
调用:UnionGetFullSystemDateTime(time);
结果:time = [20160505193102]
int GetFullSystemDate(char *strdate) ----获取八位的时间
{
time_t tmptime;
struct tm *tmptm;
int tmpyear;
time(&tmptime);
tmptm = (struct tm *)localtime(&tmptime);
if(tmptm->tm_year > 90)
tmpyear = 1900 + tmptm->tm_year%1900;
else
tmpyear = 2000 + tmptm->tm_year;
sprintf(strdate,"%04d%02d%02d",tmpyear,tmptm->tm_mon+1,tmptm->tm_mday);
return(0);
}
int GetSystemYear(char *stryear)-----获取系统年份
{
time_t tmptime;
struct tm *tmptm;
int tmpyear;
time(&tmptime);
tmptm = (struct tm *)localtime(&tmptime);
if(tmptm->tm_year > 90)
tmpyear = 1900 + tmptm->tm_year%1900;
else
tmpyear = 2000 + tmptm->tm_year;
sprintf(stryear,"%04d",tmpyear);
return(0);
}
阅读(1067) | 评论(0) | 转发(0) |