venerdì 7 marzo 2008

Get current time and date

Simply, use the class TTime:

TTime mytime;
mytime.HomeTime();

Home time is the same time as a wall clock would show.

Instead, to get the Universal Time (UTC), use:

mytime.UniversalTime();

Now we could convert the time&date to a string object (called descriptor in Symbian):

TBuf<100> dateStr;
_LIT(KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3");
mytime.FormatL(dateStr,KDateString);
// dateString contains "07/03/2008"
, for example

TBuf<100> timeStr;
_LIT(KTimeString,"%-B%:0%J%:1%T%:2%S%:3%+B");
mytime.FormatL(timeStr,KTimeString);
//
timeStr contains "16:10:59", for example

Nessun commento: