CTime 是一个类SYSTEMTIME 只是一个结构: typedef struct _SYSTEMTIME { WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay; WORD wHour; WORD wMinute; WORD wSecond; WORD wMilliseconds; } SYSTEMTIME; 可如下方式取得时间 SYSTEMTIME systime; GetSystemTime(&systime); 两者的关系: CTime time(CTime::GetCurrentTime()); SYSTEMTIME timeDest; time.GetAsSystemTime(timeDest);
MSDN里写的很明白
CTime( );
CTime( const CTime& timeSrc );
CTime( time_t time );
CTime( int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, int nDST = -1 );
CTime( WORD wDosDate, WORD wDosTime, int nDST = -1 );
CTime( const SYSTEMTIME& sysTime, int nDST = -1 );
CTime( const FILETIME& fileTime, int nDST = -1 );CTime time(CTime::GetCurrentTime());
SYSTEMTIME timeDest;
time.GetAsSystemTime(timeDest);CTime time2(timeDest);
2、好好看看CTime::Format的帮助吧
至于SYSTEMTIME它就是一个结构体,我想格式化输出你应该会吧CString szTime;
szTime.Format(_T("%4d-%02d-%02d %02d:%02d:%02d"), st.wYear, st.wMonth, ...
如果想显示时间的话就格式化成一个CString。像楼上所说的那样。
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME;
可如下方式取得时间
SYSTEMTIME systime;
GetSystemTime(&systime);
两者的关系:
CTime time(CTime::GetCurrentTime());
SYSTEMTIME timeDest;
time.GetAsSystemTime(timeDest);
CTime是MFC函数
详情见MSDN.
如何将这time1变量转换成CString呢?
好像,格式化只对SYSTEMTIME有用吧。
CString szTime;
szTime.Format(_T("%4d-%02d-%02d"), time1.GetYear(), time1.GetMonth(), time1.GetDay() );