|
||
The following code fragment formats the day number, date suffix and month name as text into a supplied descriptor. The function in the code fragment assumes that the descriptor is sufficiently big:
void formatDateTime(TDes& aBuffer,TDateTime aDateTime)
{
_LIT(KFormatTxt,"Date as text: %d%S %S\n");
aBuffer.Format(KFormatTxt,aDateTime.Day()+1,&(TDateSuffix(aDateTime.Day())),&(TMonthName(aDateTime.Month())));
}
Note the following:
TDateSuffix
and TMonthName
are
descriptors
A TDateSuffix
object can contain a maximum of 4
characters
A TMonthName
object can contain a maximum of 32 characters
In this example, both objects are constructed with a TInt
value representing the day number within the
month for the TDateSuffix
object, and the month number for the TMonthName
object. Both numbers are values offset from zero.
The numbers are used to generate the appropriate text. For example, for a
TDateSuffix
object, a value of zero gives "st", (first day
of the month), one gives "nd" etc.