我要得到系统时间
char CCuTime[30];
struct tm*newtime;
long aaTime;
time(&aaTime);
newtime=localtime(&aaTime);
我要的是时间,如何从newtime中提取出时间???
谢谢了
char CCuTime[30];
struct tm*newtime;
long aaTime;
time(&aaTime);
newtime=localtime(&aaTime);
我要的是时间,如何从newtime中提取出时间???
谢谢了
#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不是很简单吗?
如用VC++的话,在 tm 上点右键,选 goto defination of tm
GetLocalTime是怎摸定义的????
localtime( &long_time ); 替换成GetLocalTime吗???
我真的不知怎摸用
谢谢了!
谢谢二位了
CTime tm;
tm=CTime::GetCurrentTime();
看CTime的函数,什么时间都可以得到!
MSDN上就是这么写的:
CTime t = CTime::GetCurrentTime();
LPSYSTEMTIME lpSystemTime // system time
);
LPSYSTEMTIME lpSysTime;
GetLocalTime(lpSysTime);
WORD wYera = lpSysTime->wYear;
WORD wDay = lpSysTime->wDay;
.
.
.
.
GetLocalTime(&stm);
WORD wYera = stm.wYear;
WORD wDay = stm.wDay;