2009-11-10 100 views
0

代碼:轉換時間紀元時間格式

TBuf<50> TimeDesc; 
TBuf <50> singleLog; 
TTime time = event.Time(); 
_LIT(KTimeFormat,"%I%:1%T%:1%S %B"); 
RTz tzServer; 
User::LeaveIfError(tzServer.Connect()); 
CleanupClosePushL(tzServer); 
CTzConverter* tzConverter = CTzConverter::NewL(tzServer); 
CleanupStack::PushL(tzConverter); 
tzConverter->ConvertToLocalTime(time); 
time.FormatL(TimeDesc,KTimeFormat); 
singleLog.Append(TimeDesc); 
singleLog.Append('|'); 

如何這次劃時代的時間格式轉換?

回答

0

我發現這個函數,它接受一個Unix紀元時間戳,並返回一個TTime

// This function converts a Unix Epoch timestamp to a TTime 
TTime UnixToEpocTimeL(TUint32 aTimestamp) 
{ 

// define the start of the Unix Epoch as beginning of Jan 1, 1970 
_LIT(KUnixEpoch, "19700000:"); 

// Create a new time variable, and give it the starting value of Jan 1, 1970 
TTime time; 
User::LeaveIfError(time.Set(KUnixEpoch)); 

// The timestamp is the number of seconds since Jan 1, 1970 
// Add the number of seconds in the timestamp to start date. 
TTimeIntervalSeconds secs(aTimeStamp); 
time += secs; 

// the variable 'time' now contains the requested datetime 
return time; 
} 

http://discussion.forum.nokia.com/forum/showthread.php?t=110494


更新:我不知道很多關於這個(我也不具有任何這裏測試它的方式!),但我試圖添加詳細的評論,解釋我認爲它的工作原理。你可以添加類似於你的代碼的東西,甚至可以添加一個函數並直接調用它。

+0

謝謝 給出錯誤 未定義的標識符「KUnixEpoch」 未定義的標識符「KUnixEpoch」 我應該包括某種形式的頭文件還是什麼? – sonia 2009-11-10 13:13:10

+0

恐怕你在這方面超出了我的知識 - 這個例子是一個剪切和粘貼的工作。我以爲'_LIT(KUnixEpoch,「19700000:」);'定義了'KUnixEpoch'。我會嘗試添加一些評論,說明我認爲它在做什麼 – 2009-11-10 17:10:23