其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
C语言: 按照格式返回系统时间的的函数[开发备忘]

作者:未知 来源:月光软件站 加入时间:2005-5-13 月光软件站

/*
功能描述:获取当前的系统时间格式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);
  
  
}




相关文章

相关软件