全部博文(668)
分类:
2008-07-02 14:47:25
/*
功能描述:获取当前的系统时间格式YYYYMMDDhhmmss,精确到秒
参数描述:char * curtime传地址方式传入的参数,用于返回指定格式的时间字符串,
int flag: 1-将时间做成YYYYMMDDhhmmss格式 2-将时间做成YYYY-MM-DD hh:mm:ss格式 3-将时间做成YYYYMMDD格式
返回参数:无 (格式为YYYYMMDDhhmmss或者为YYYY-MM-DD hh:mm:ss的字符串)
*/
void get_curtime(int flag,char * timeformat)
{
char outstr[128];
char str[100];
time_t t;
struct tm *gmt, *area;
t = time(NULL);
area = localtime(&t);
memset(outstr,0x0,sizeof(outstr));
if(flag==1)
{
sprintf(str,"%4d",1900+area->tm_year);
strcat(outstr,str);
sprintf(str,"%02d",area->tm_mon+1);
strcat(outstr,str);
sprintf(str,"%02d",area->tm_mday);
strcat(outstr,str);
sprintf(str,"%02d",area->tm_hour);
strcat(outstr,str);
sprintf(str,"%02d",area->tm_min);
strcat(outstr,str);
sprintf(str,"%02d",area->tm_sec);
strcat(outstr,str);
}
else if(flag==3)
{
sprintf(str,"%4d",1900+area->tm_year);
strcat(outstr,str);
sprintf(str,"%02d",area->tm_mon+1);
strcat(outstr,str);
sprintf(str,"%02d ",area->tm_mday);
strcat(outstr,str);
}
else
{
sprintf(str,"%4d-",1900+area->tm_year);
strcat(outstr,str);
sprintf(str,"%02d-",area->tm_mon+1);
strcat(outstr,str);
sprintf(str,"%02d ",area->tm_mday);
strcat(outstr,str);
sprintf(str,"%02d:",area->tm_hour);
strcat(outstr,str);
sprintf(str,"%02d:",area->tm_min);
strcat(outstr,str);
sprintf(str,"%02d",area->tm_sec);
strcat(outstr,str);
}
strcpy(timeformat,outstr);
}