Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

4.1 Example

The point is that RWDate allows you to quickly and easily manipulate the calendar dates you're most likely to use. Here is an example that demonstrates the virtuosity of the class.

Let's print out the date when ENIAC first started, 14 February 1945, then calculate and print the date of the previous Sunday, using the global locale:

#include <rw/rwdate.h>
#include <rw/rstream.h> 
int main(){
// ENIAC start date
RWDate d(14, "February", 1945); 
// Today
RWDate today; 
cout << d.asString("%A, %B %d 19%y")
<< " was the day the ENIAC computer was" << endl
<< "first turned on. " 
<< today - d << " days have gone by since then. " << endl
<< d.previous("Sunday").asString("%A, %B %d 19%y") << endl
<< "is the Sunday previous to the day" << endl
<< "the ENIAC computer was first turned on. " << endl; 
return 0;
}

Program Output:

Wednesday, February 14 1945 was the day the ENIAC computer was
first turned on.  19753 days have gone by since then.
Sunday, February 11 1945
is the Sunday previous to the day
the ENIAC computer was first turned on.

In this calculation, notice that the number of days that have passed depends on when you run the program.


Previous fileTop of documentContentsIndexNext file
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.