如何将COleDateTime转换为某种可以轻松转换回来的整数表示形式。
答案 0 :(得分:4)
我认为最简单的方法是COleDateTimeSpan
如下:
// Create an epoch
static COleDateTime epoch( 2000, 1, 1, 0, 0, 0 );
// Convert to integer
COleDateTime someTime; // initialize it from somewhere
__int64 nOleDateTimeAsInt = static_cast<__int64>( (someTime - epoch).totalSeconds() );
// Create from integer
COleDateTimeSpan span( nOleDateTimeAsInt / SecondsInDay,
(nOleDateTime % SecondsInDay) / SecondsInHour,
(nOleDateTime % SecondsInHour) / SecondsInMinute,
(nOleDateTime % SecondsInMinute) );
COleDateTime someTime( epoch + span );