Updated Boost datetime Examples Translated (markdown)

Howard Hinnant
2017-07-07 18:16:04 -04:00
parent 018dda723c
commit 8c3531f259

@@ -153,72 +153,72 @@ main()
``` ```
<a name="Localization_Demonstration"></a> <a name="Localization_Demonstration"></a>
### Localization Demonstration ### Localization Demonstration
```c++
#include "date.h"
#include <iomanip>
#include <iostream>
#include "date.h" // Define a series of char arrays for short and long name strings
#include <iomanip> // to be associated with German date output (US names will be
#include <iostream> // retrieved from the locale).
const char* const de_long_month_names[] =
{
"Januar", "Februar", "Marz", "April", "Mai",
"Juni", "Juli", "August", "September", "Oktober",
"November", "Dezember", "NichtDerMonat"
};
// Define a series of char arrays for short and long name strings const char* const de_long_weekday_names[] =
// to be associated with German date output (US names will be {
// retrieved from the locale). "Sonntag", "Montag", "Dienstag", "Mittwoch",
const char* const de_long_month_names[] = "Donnerstag", "Freitag", "Samstag"
{ };
"Januar", "Februar", "Marz", "April", "Mai",
"Juni", "Juli", "August", "September", "Oktober",
"November", "Dezember", "NichtDerMonat"
};
const char* const de_long_weekday_names[] = int
{ main()
"Sonntag", "Montag", "Dienstag", "Mittwoch", {
"Donnerstag", "Freitag", "Samstag" using namespace date;
};
int // create some gregorian objects to output
main() auto d1 = 2002_y/oct/1;
{ auto m = d1.month();
using namespace date; auto wd = weekday{d1};
// create some gregorian objects to output
auto d1 = 2002_y/oct/1;
auto m = d1.month();
auto wd = weekday{d1};
using namespace std;
// output the date in German using short month names
cout << d1.day() << '.'
<< setw(2) << static_cast<unsigned>(d1.month())
<< '.' << d1.year() << '\n';
cout << de_long_month_names[static_cast<unsigned>(m)-1] << '\n';
cout << de_long_weekday_names[static_cast<unsigned>(wd)] << '\n';
cout << static_cast<unsigned>(d1.month()) << '/' << d1.day()
<< '/' << d1.year() << '\n';
cout << d1.year() << '-' << d1.month() << '-' << d1.day() << '\n';
}
using namespace std;
// output the date in German using short month names
cout << d1.day() << '.'
<< setw(2) << static_cast<unsigned>(d1.month())
<< '.' << d1.year() << '\n';
cout << de_long_month_names[static_cast<unsigned>(m)-1] << '\n';
cout << de_long_weekday_names[static_cast<unsigned>(wd)] << '\n';
cout << static_cast<unsigned>(d1.month()) << '/' << d1.day()
<< '/' << d1.year() << '\n';
cout << d1.year() << '-' << d1.month() << '-' << d1.day() << '\n';
}
```
If your OS supports the `std::locale("de_DE")` the above can be simplified to: If your OS supports the `std::locale("de_DE")` the above can be simplified to:
```c++
#include "date.h"
#include "tz.h"
#include <iostream>
#include "date.h" int
#include "tz.h" main()
#include <iostream> {
using namespace date;
int // create some gregorian objects to output
main() auto d1 = 2002_y/oct/1;
{
using namespace date;
// create some gregorian objects to output
auto d1 = 2002_y/oct/1;
using namespace std;
locale loc("de_DE");
cout << format(loc, "%x\n", local_days{d1});
cout << format(loc, "%B\n", local_days{d1});
cout << format(loc, "%A\n", local_days{d1});
cout << format(loc, "%D\n", local_days{d1});
cout << format(loc, "%F\n", local_days{d1});
}
using namespace std;
locale loc("de_DE");
cout << format(loc, "%x\n", local_days{d1});
cout << format(loc, "%B\n", local_days{d1});
cout << format(loc, "%A\n", local_days{d1});
cout << format(loc, "%D\n", local_days{d1});
cout << format(loc, "%F\n", local_days{d1});
}
```
<a name="Date_Period_Calculations"></a> <a name="Date_Period_Calculations"></a>
### Date Period Calculations ### Date Period Calculations