Using Date and Time Utilities

Stores dates in universal time format and supports the parsing of dates.

Introduction

TInternetDate class stores the date in universal time and provides the functionality to parse internet style dates in different formats into TDateTime and RFC 1123 dates. This class handles the 8-bit descriptors only.

TInternetDate supports parsing of the following date time formats:

  • Sun, 06 Nov 1994 08:49:37 GMT, RFC 822 and RFC 1123

  • Sunday, 06-Nov-94 08:49:37 GMT, RFC 850

  • Sun Nov 6 08:49:37 1994 ANSI C's asctime() format

Converting date to text format

The following code fragment constructs a TInternetDate object from a TDateTime object. It converts the date ' 2006,EJanuary,17,06,36,30,000000 ' to the text form, that is ' Wed, 17 Jan 2006 06:36:30 GMT '.

       //create a date time object
TDateTime time(2006,EJanuary,17,06,36,30,000000);  TInternetDate internetDate(time);

//get the text form "Wed, 17 Jan 2006 06:36:30 GMT"
HBufC8* textDate = internetDate.InternetDateTimeL(TInternetDate::ERfc1123Format);
CleanupStack::PushL(textDate);

//use textDate here
CleanupStack::PopAndDestroy(textDate);
      

Setting text form of date

Use TInternetDate::SetDateL() to set the text from of the date. Construct a TInternetDate object [date string] from a desciptor which contains date.

       _LIT8(KTextDate, "Wed, 17 Jan 2006 06:36:30 GMT");
TInternetDate internetDate1; 

//set date time, "Wed, 17 Jan 2006 06:36:30 GMT"
internetDate1.SetDateL(KTextDate); 

//convert textDate to Date time format
TDateTime time1 = internetDate1.DateTime();
      

The code fragment sets the text form of date, " Wed, 17 Jan 2006 06:36:30 GMT " and converts it to DateTime format.