代码:
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 :(得分:0)
我发现这个函数需要一个Unix Epoch时间戳并返回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
更新:我对此不太了解(我也没有办法在这里测试它!)但是我试图添加详细的评论来解释我认为它是如何工作的。您可以添加类似于代码的内容,甚至可以添加一个函数并直接调用它。