Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2209739
  • 博文数量: 668
  • 博客积分: 10016
  • 博客等级: 上将
  • 技术积分: 8588
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-29 19:22
文章分类

全部博文(668)

文章存档

2011年(1)

2010年(2)

2009年(273)

2008年(392)

分类:

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);
  
  
}

阅读(1146) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~