当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

    摘要: 如何在bean中调用连接池,研究好久了也没明白,望高手指教... ......
 ·是谁错了    »显示摘要«
    摘要: 我想up一下我的一个200分贴,但出来了 "连续的回复不能超过3次" 的出错信息,而我实际只连续回复(参与发言)过2次,请问究竟是那一个软件出错了? 是 ie,还是csdn的web服务器? ......


:C语言里,怎么提取系统当前的日期,并转换为长整型谢谢大家。

如:Mon   Sep   22   15:58:27   2003   转换为   20030922     呢?或者说有其它的方法也行,谢谢大家。  
   
   
  附一函数,这个时间就是这样提取的,谢谢大家。ANSI标准的函数localtime(),描述如下:  
  Synopsis:  
   
  #include   <time.h>  
  struct   tm   *   localtime(   const   time_t   *timer   );  
   
  struct     tm   {  
      int   tm_sec;       /*   seconds   after   the   minute   --   [0,61]   */  
      int   tm_min;       /*   minutes   after   the   hour       --   [0,59]   */  
      int   tm_hour;     /*   hours   after   midnight           --   [0,23]   */  
      int   tm_mday;     /*   day   of   the   month                   --   [1,31]   */  
      int   tm_mon;       /*   months   since   January           --   [0,11]   */  
   
      int   tm_year;     /*   years   since   1900                                       */  
      int   tm_wday;     /*   days   since   Sunday                 --   [0,6]     */  
      int   tm_yday;     /*   days   since   January   1           --   [0,365]*/  
      int   tm_isdst;   /*   Daylight   Savings   Time   flag   */  
  };  
   
  Description:  
   
  The   localtime   functions   convert   the   calendar   time   pointed   to   by   timer   into   a   structure   of   type     tm,   of   time   information,   expressed   as   local   time.     Whenever   localtime   is   called,   the     tzset   function   is   also   called.  
   
  The   calendar   time   is   usually   obtained   by   using   the     time   function.     That   time   is   Coordinated   Universal   Time   (UTC)   (formerly   known   as   Greenwich   Mean   Time   (GMT)).  
   
  The   time   set   on   the   computer   with   the   DOS   time   command   and   the   DOS   date   command   reflects   the   local   time.     The   environment   variable   TZ   is   used   to   establish   the   time   zone   to   which   this   local   time   applies.     See   the   section   The   TZ   Environment   Variable   for   a   discussion   of   how   to   set   the   time   zone.  
   
  Returns:  
   
  The   localtime   functions   return   a   pointer   to   a     tm   structure   containing   the   time   information.  
   
  See   Also:  
   
  asctime,   clock,   ctime,   difftime,   gmtime,   mktime,   strftime,   time,   tzset  
   
  Example:  
   
  #include   <stdio.h>  
  #include   <time.h>  
   
  void   main()  
      {  
          time_t   time_of_day;  
          auto   char   buf[26];  
          auto   struct   tm   tmbuf;  
   
          time_of_day   =   time(   NULL   );  
          _localtime(   &time_of_day,   &tmbuf   );  
          printf(   "It   is   now:   %s",   _asctime(   &tmbuf,   buf   )   );  
      }  
   
  produces   the   following:  
   
  It   is   now:   Sat   Mar   21   15:58:27   1987  
   
  Classification:  
   
  localtime   is   ANSI  
 

NO.1   作者: buzhiming99

char   szTime[14];  
  SYSTEMTIME   m_systime;  
  GetLocalTime(&m_systime);  
  sprintf(szTime,"%04d%02d%02d%02d%02d%02d",m_systime.wYear,m_systime.wMonth,m_systime.wDay,m_systime.wHour,m_systime.wMinute,m_systime.wSecond);  
   
   
 

NO.2   作者: CreaTive1911

/*   TIMES.C   illustrates   various   time   and   date   functions   including:  
    *             time                         _ftime                     ctime               asctime  
    *             localtime               gmtime                     mktime             _tzset  
    *             _strtime                 _strdate                 strftime  
    *  
    *   Also   the   global   variable:  
    *             _tzname  
    */  
   
  #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   );  
  }  
   
   
  C语言风格的,几乎有所有的时间格式,

NO.3   作者: jys0793

功     能:   取DOS日期    
  用     法:   void   getdate(struct   *dateblk);    
  程序例:    
   
  #include   <dos.h>    
  #include   <stdio.h>    
   
  int   main(void)    
  {    
        struct   date   d;    
   
        getdate(&d);    
        printf("The   current   year   is:   %d\n",    
        d.da_year);    
        printf("The   current   day   is:   %d\n",    
        d.da_day);    
        printf("The   current   month   is:   %d\n",    
        d.da_mon);    
        return   0;    
  }    
 

NO.4   作者: liao2001

sprintf()+格式输入  
 


    摘要: 前几天去wrox官方网站看了一下,原来有得下载的,现在竟然没了。 那位兄弟手里有的,可否上传给我。 上传地址:http://www.kakai-info.com/994/up.aspx 或者email给我:我的邮箱地址是outspaceman@tom.com 谢谢了。 ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE