我要得到系统时间
char CCuTime[30];
struct tm*newtime;

long aaTime;
time(&aaTime);
newtime=localtime(&aaTime);
我要的是时间,如何从newtime中提取出时间???
谢谢了

解决方案 »

  1.   

    #include <stdio.h>
    #include <string.h>
    #include <time.h>void main( void )
    {
      struct tm *newtime;
      char am_pm[] = "AM";
      time_t long_time;  time( &long_time );                /* Get time as long integer. */
      newtime = localtime( &long_time ); /* Convert to local time. */  if( newtime->tm_hour > 12 )        /* Set up extension. */
      strcpy( am_pm, "PM" );
      if( newtime->tm_hour > 12 )        /* Convert from 24-hour */
      newtime->tm_hour -= 12;    /*   to 12-hour clock.  */
      if( newtime->tm_hour == 0 )       /*Set hour to 12 if midnight. */
      newtime->tm_hour = 12;  printf( "%.19s %s\n", asctime( newtime ), am_pm );
    }或者使用GetLocalTime不是很简单吗?
      

  2.   

    在 time.h 中可以找到(通常位于编译器的include文件夹下)
    如用VC++的话,在 tm 上点右键,选 goto defination of tm
      

  3.   

    tm structure Used by asctime, gmtime, localtime, mktime, and strftime to store and retrieve time information.  see TIME.H
      

  4.   

    请问sans(sans) :
    GetLocalTime是怎摸定义的????
    localtime( &long_time ); 替换成GetLocalTime吗???
    我真的不知怎摸用
    谢谢了!
    谢谢二位了
      

  5.   

    有一个简单的方法:
    CTime tm;
    tm=CTime::GetCurrentTime();
    看CTime的函数,什么时间都可以得到!
      

  6.   

    是啊,简单的问题别搞复杂了,同意楼上的。
    MSDN上就是这么写的:
    CTime t = CTime::GetCurrentTime();
      

  7.   

    VOID GetLocalTime(
      LPSYSTEMTIME lpSystemTime   // system time
    );
    LPSYSTEMTIME lpSysTime;
    GetLocalTime(lpSysTime);
    WORD wYera = lpSysTime->wYear;
    WORD wDay = lpSysTime->wDay;
    .
    .
    .
    .
      

  8.   

    SYSTEMTIME stm={0};
    GetLocalTime(&stm);
    WORD wYera = stm.wYear;
    WORD wDay = stm.wDay;
      

  9.   

    CTime tm=CTime::GetCurrentTime();最简单
      

  10.   

    SYSTEMTIME  sysTime;GetSystemTime(&sysTime);sysTime.wYear ............