DB Interface Module User’s Guide : PART III Using Advanced Features : Chapter 13 Internationalization : Data Formatting : RWDBDateTime
RWDBDateTime
Class RWDBDateTime used to be the primary class for representing and manipulating dates and time in the DB Interface Module; however, RWDBDateTime has been deprecated. New code should be written using class RWDateTime.
The DB Interface Module does not include an operator<< for ostreams and instances of RWDBDateTime. The following example shows how to make an operator<< that outputs an RWDBDateTime correctly with whatever locale was imbued in the ostream.
 
ostream&
operator<<(ostream& o, const RWDBDateTime& dt)
{
const RWLocale& localeOfTheStream = RWLocale::of(o);
return o << dt.asString('\0', RWZone::local(), localeOfTheStream);
}
RWDate
RWDate is a class from the Essential Tools Module that can also be used as a database datatype. The DB Interface Module can handle any formatting issues without intervention when getting this type in and out of a database, as it can for RWDateTime. Of course, as in “RWDateTime”, the trick is getting localized information from a user to initialize an instance of RWDate. The Essential Tools Module gives several options.
First, there is a constructor that takes a reference to an istream and a reference to an RWLocale. This allows direct initialization of the RWDate instance from the istream.
A second technique is shown in the example below. A string initialized with a representation of a localized date is created and then converted to an RWDate with the assistance of an RWLocale reference.
 
void
demoI18NDate()
{
RWDate aDate("26 Mai 1998", RWLocaleSnapshot("de"));
 
cout << "in the US: "
<< aDate.asString("%d %b %Y", RWLocaleSnapshot("en_US"))
<< endl;
cout << "in France: "
<< aDate.asString("%d %b %Y", RWLocaleSnapshot("fr"))
<< endl;
}
The output for this example should be:
 
in the US: 26 May 1998
in France: 26 mai 1998