用SYSTEMTIME,可以精确到毫秒 typedef struct _SYSTEMTIME { WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay; WORD wHour; WORD wMinute; WORD wSecond; WORD wMilliseconds; } SYSTEMTIME;GetSystemTime()函数用于取时间,SetSystemTime()用于设置系统时间,另外,你还可以用GetLocalTime()取得当地的当前时间,而不是UTC时间,当然,对应的有SetLocalTime函数;UTC时间和当地时间可以通过使用SetTimeZoneInformation函数设置当前时区参数来控制;用SystemTimeToFileTime函数可以将SYSTEMTIME格式转换为FILETIME格式;
CTime::GetCurrentTime Returns a CTime object that represents the current time.static CTime WINAPI GetCurrentTime( ) throw( ); Example // Example for CTime::GetCurrentTime CTime t = CTime::GetCurrentTime();
CTime::GetDay Returns the day represent by the CTime object.int GetDay( ) const throw( ); Return Value Returns the day of the month, based on local time, in the range 1 through 31.Res This function calls GetLocalTm, which uses an internal, statically allocated buffer. The data in this buffer is overwritten because of calls to other CTime member functions.Example // Example for CTime::GetDay, CTime::GetMonth, and CTime::GetYear CTime t( 1999, 3, 19, 22, 15, 0 ); // 10:15 PM March 19, 1999 ATLASSERT( t.GetDay() == 19 ); ATLASSERT( t.GetMonth() == 3 ); ATLASSERT( t.GetYear() == 1999 );
CTime tTime = CTime::GetCurrentTime();
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME;GetSystemTime()函数用于取时间,SetSystemTime()用于设置系统时间,另外,你还可以用GetLocalTime()取得当地的当前时间,而不是UTC时间,当然,对应的有SetLocalTime函数;UTC时间和当地时间可以通过使用SetTimeZoneInformation函数设置当前时区参数来控制;用SystemTimeToFileTime函数可以将SYSTEMTIME格式转换为FILETIME格式;
法一: CTime time;
time=CTime::GetCurrentTime();
法二:GetSystemTime(&systime);
或者
CTime time=CTime::GetLocalTime();
Returns a CTime object that represents the current time.static CTime WINAPI GetCurrentTime( ) throw( );
Example
// Example for CTime::GetCurrentTime
CTime t = CTime::GetCurrentTime();
Returns the day represent by the CTime object.int GetDay( ) const throw( );
Return Value
Returns the day of the month, based on local time, in the range 1 through 31.Res
This function calls GetLocalTm, which uses an internal, statically allocated buffer. The data in this buffer is overwritten because of calls to other CTime member functions.Example
// Example for CTime::GetDay, CTime::GetMonth, and CTime::GetYear
CTime t( 1999, 3, 19, 22, 15, 0 ); // 10:15 PM March 19, 1999
ATLASSERT( t.GetDay() == 19 );
ATLASSERT( t.GetMonth() == 3 );
ATLASSERT( t.GetYear() == 1999 );
COleVariant varTemp("2004-8-11");
COleDateTime oleTime(varTemp);
这样就可以将字符串“2004-8-11”最方便地转换为日期了。