Categories: Symbian C++ | Code Examples | S60 3rd Edition | S60 3rd Edition, Feature Pack 1 | S60 3rd Edition, Feature Pack 2
This page was last modified 05:31, 7 March 2008.
CS000847 - Converting time zones
From Forum Nokia Wiki
| ID | CS000847 | Creation date | March 7, 2008 |
| Platform | S60 3rd Edition S60 3rd Edition, FP1 S60 3rd Edition, FP2 Beta | Tested on devices | Nokia E61i Nokia E90 Communicator Nokia N95 8GB Nokia 6220 Classic |
| Category | Symbian C++ | Subcategory | Base/System |
| APIs | None | Classes | TTime RTz CTzConverter CTzId |
| Methods | TTime::UniversalTime() TTime::FormatL() CTzConverter::ConvertToLocalTime() |
Overview
This code snippet demonstrates how to convert the time between different time zones. The snippet demonstrates the following functionality:
- Displaying UTC time
- Converting UTC time to local time
- Converting UTC time to a specific time zone (Europe/Helsinki)
MMP file
The following libraries are required:
LIBRARY tzclient.lib
Source file
#include <aknnotewrappers.h> // CEikonEnv::InfoWinL() #include <tz.h> // RTz, CTzId #include <tzconverter.h> // CTzConverter
TTime utcTime; TTime time; TBuf<100> buffer; // Times are formatted according to the European standard with AM/PM marking. // For example: 26/02/2008 1:07:03 pm _LIT(KFormatTxt, "%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B"); // ---------------------------------------------------------------------------- // Obtain the universal time (UTC), format it, and display it utcTime.UniversalTime(); utcTime.FormatL(buffer, KFormatTxt); _LIT(KUtc, "UTC time"); iEikonEnv->InfoWinL(buffer, KUtc); // ---------------------------------------------------------------------------- // Connect to the time zone server RTz tzServer; User::LeaveIfError(tzServer.Connect()); CleanupClosePushL(tzServer); // ---------------------------------------------------------------------------- // Create a time zone converter CTzConverter* tzConverter = CTzConverter::NewL(tzServer); CleanupStack::PushL(tzConverter); // ---------------------------------------------------------------------------- // Convert from UTC to local time time = utcTime; tzConverter->ConvertToLocalTime(time); // Format and display the local time time.FormatL(buffer, KFormatTxt); _LIT(KLocal, "Local time"); iEikonEnv->InfoWinL(buffer, KLocal); // ---------------------------------------------------------------------------- // Create a time zone ID object for Europe/Helsinki (GMT+2) _LIT8(KHelsinki, "Europe/Helsinki"); CTzId* tzId = CTzId::NewL(KHelsinki); CleanupStack::PushL(tzId); // Convert UTC time to local time for Europe/Helsinki time = utcTime; TInt results = tzConverter->ConvertToLocalTime(time, *tzId); if (results == KErrNone) { // Conversion successful. Display the time. time.FormatL(buffer, KFormatTxt); _LIT(KLocalHelsinki, "Local time in Europe/Helsinki"); iEikonEnv->InfoWinL(buffer, KLocalHelsinki); } else { _LIT(KError, "Error while converting"); _LIT(KErrorHeading, "Error"); iEikonEnv->InfoWinL(KError, KErrorHeading); } CleanupStack::PopAndDestroy(3); // tzId, tzConverter, tzServer
Postconditions
Several different time conversions are done.
See also
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 请教:关于线程中使用CImageDecoder | ch2000pro | Symbian | 10 | 2007-07-19 02:12 |
| MBM file Pixel size | surprisedisco | Symbian Tools & SDKs | 3 | 2007-07-12 04:00 |
| Sms date and time | zafalimited | General Messaging | 0 | 2006-04-24 14:44 |
| Sms date and time | zafalimited | Mobile Java General | 3 | 2006-04-26 02:13 |
| FLV video player for Symbian | resca79 | Python | 2 | 2007-07-27 13:10 |

