CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  工具平台和程序库

标准c中如何得到系统的日期和时间,比如"200311032011"

楼主weiyunfei()2003-11-03 19:42:34 在 C/C++ / 工具平台和程序库 提问

20031103201110即2003年11月3日20点11分10秒 问题点数:0、回复次数:5Top

1 楼daizh()回复于 2003-11-03 20:31:22 得分 0

#include   <time.h>  
  #include   <stdio.h>  
  #include   <sys/types.h>  
  #include   <sys/timeb.h>  
  #include   <string.h>  
   
  void   main()  
  {  
          char   tmpbuf[128],   ampm[]   =   "AM";  
          time_t   ltime;  
          struct   _timeb   tstruct;  
          struct   tm   *today,   *gmt,   xmas   =   {   0,   0,   12,   25,   11,   93   };  
   
          /*   Set   time   zone   from   TZ   environment   variable.   If   TZ   is   not   set,  
            *   the   operating   system   is   queried   to   obtain   the   default   value    
            *   for   the   variable.    
            */  
          _tzset();  
   
          /*   Display   operating   system-style   date   and   time.   */  
          _strtime(   tmpbuf   );  
          printf(   "OS   time:\t\t\t\t%s\n",   tmpbuf   );  
          _strdate(   tmpbuf   );  
          printf(   "OS   date:\t\t\t\t%s\n",   tmpbuf   );  
   
          /*   Get   UNIX-style   time   and   display   as   number   and   string.   */  
          time(   &ltime   );  
          printf(   "Time   in   seconds   since   UTC   1/1/70:\t%ld\n",   ltime   );  
          printf(   "UNIX   time   and   date:\t\t\t%s",   ctime(   &ltime   )   );  
   
          /*   Display   UTC.   */  
          gmt   =   gmtime(   &ltime   );  
          printf(   "Coordinated   universal   time:\t\t%s",   asctime(   gmt   )   );  
   
          /*   Convert   to   time   structure   and   adjust   for   PM   if   necessary.   */  
          today   =   localtime(   &ltime   );  
          if(   today->tm_hour   >   12   )  
          {  
        strcpy(   ampm,   "PM"   );  
        today->tm_hour   -=   12;  
          }  
          if(   today->tm_hour   ==   0   )     /*   Adjust   if   midnight   hour.   */  
        today->tm_hour   =   12;  
   
          /*   Note   how   pointer   addition   is   used   to   skip   the   first   11    
            *   characters   and   printf   is   used   to   trim   off   terminating    
            *   characters.  
            */  
          printf(   "12-hour   time:\t\t\t\t%.8s   %s\n",  
                asctime(   today   )   +   11,   ampm   );  
   
          /*   Print   additional   time   information.   */  
          _ftime(   &tstruct   );  
          printf(   "Plus   milliseconds:\t\t\t%u\n",   tstruct.millitm   );  
          printf(   "Zone   difference   in   seconds   from   UTC:\t%u\n",    
                            tstruct.timezone   );  
          printf(   "Time   zone   name:\t\t\t\t%s\n",   _tzname[0]   );  
          printf(   "Daylight   savings:\t\t\t%s\n",    
                            tstruct.dstflag   ?   "YES"   :   "NO"   );  
   
          /*   Make   time   for   noon   on   Christmas,   1993.   */  
          if(   mktime(   &xmas   )   !=   (time_t)-1   )  
        printf(   "Christmas\t\t\t\t%s\n",   asctime(   &xmas   )   );  
   
          /*   Use   time   structure   to   build   a   customized   time   string.   */  
          today   =   localtime(   &ltime   );  
   
          /*   Use   strftime   to   build   a   customized   time   string.   */  
          strftime(   tmpbuf,   128,  
                    "Today   is   %A,   day   %d   of   %B   in   the   year   %Y.\n",   today   );  
          printf(   tmpbuf   );  
  }  
  Top

2 楼smalltalk(老徐)回复于 2003-11-03 21:41:29 得分 0

老徐已经在这里给你正解了!  
  http://expert.csdn.net/Expert/topic/2423/2423498.xml?temp=.344784Top

3 楼heguobaoceo(awen)回复于 2003-11-03 21:50:45 得分 0

厉害  
  Top

4 楼cym64039(青枫)回复于 2003-11-04 16:00:11 得分 0

在linux下  
  char   *getnowdate(char   *nowdate)  
  {  
  time_t   timer;  
  struct   tm   *ltm;  
  char   ndate[20];  
   
  memset(ndate,0,sizeof(nowdate));  
  timer   =   time(NULL);  
  ltm   =   localtime(&timer);  
  sprintf(ndate,"%04d%02d%02d%02d%02d%02d",  
                  ltm->tm_year   +   1900,  
                  ltm->tm_mon   +   1,  
                  ltm->tm_mday,  
                  ltm->tm_hour,  
                  ltm->tm_min,  
                  ltm->tm_sec);  
  strcpy(nowdate,ndate);  
   
  return   nowdate;  
  }Top

5 楼fingerfox(狐狸【人不要脸,天下无敌】)回复于 2003-11-04 16:24:57 得分 0

WINDOW:  
  SYSTEMTIME   st;  
  GetLoadTime(&st);  
  GetSystemTime(&st);Top

相关问题

  • 标准C++中,如何获得当前日期。
  • 如何获得一个文件的日期?(标准C)
  • ? 如何获得一个文件的日期?(标准C)
  • C++标准库.
  • 标准C
  • 标准C++ !!!!
  • c标准ISO9899
  • c#日期问题
  • 急求C/C++标准库
  • 在标准 C 中……

关键词

  • date
  • ltm
  • d%02d%02
  • ltime
  • tmpbuf
  • ndate
  • nowdate
  • tm
  • gmt
  • timer

得分解答快速导航

  • 帖主:weiyunfei

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo