tags:

views:

143

answers:

1

Code:

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('|');

How to convert this time in epoch time format?

A: 

I found this function which takes a Unix Epoch timestamp and returns a 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


UPDATE: I don't know much about this (nor do I have any way of testing it here!) but I have tried to add detailed comments explaining how I think it works. You can either add something similar to your code, or even add this a function and call it directly.

Colin Pickard
Thanksgives errorundefined identifier 'KUnixEpoch'undefined identifier 'KUnixEpoch'should i include some kind of header files or what?
sonia
I'm afraid you're getting beyond my knowledge in this area - this example was a cut and paste job. I thought the line `_LIT(KUnixEpoch, "19700000:");` defined `KUnixEpoch`. I'll try and add some comments showing what I think it is doing
Colin Pickard