mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-05 21:54:27 +02:00
Updated Boost datetime Examples Translated (markdown)
@@ -153,72 +153,72 @@ main()
|
||||
```
|
||||
<a name="Localization_Demonstration"></a>
|
||||
### Localization Demonstration
|
||||
```c++
|
||||
#include "date.h"
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
#include "date.h"
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
// Define a series of char arrays for short and long name strings
|
||||
// to be associated with German date output (US names will be
|
||||
// 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
|
||||
// to be associated with German date output (US names will be
|
||||
// retrieved from the locale).
|
||||
const char* const de_long_month_names[] =
|
||||
{
|
||||
"Januar", "Februar", "Marz", "April", "Mai",
|
||||
"Juni", "Juli", "August", "September", "Oktober",
|
||||
"November", "Dezember", "NichtDerMonat"
|
||||
};
|
||||
const char* const de_long_weekday_names[] =
|
||||
{
|
||||
"Sonntag", "Montag", "Dienstag", "Mittwoch",
|
||||
"Donnerstag", "Freitag", "Samstag"
|
||||
};
|
||||
|
||||
const char* const de_long_weekday_names[] =
|
||||
{
|
||||
"Sonntag", "Montag", "Dienstag", "Mittwoch",
|
||||
"Donnerstag", "Freitag", "Samstag"
|
||||
};
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace date;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace date;
|
||||
|
||||
// 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';
|
||||
}
|
||||
// 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';
|
||||
}
|
||||
```
|
||||
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"
|
||||
#include "tz.h"
|
||||
#include <iostream>
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace date;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
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});
|
||||
}
|
||||
// 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});
|
||||
}
|
||||
```
|
||||
<a name="Date_Period_Calculations"></a>
|
||||
### Date Period Calculations
|
||||
|
||||
|
Reference in New Issue
Block a user