From e87e529a0a0f7578a703341933ba15e53f65dd85 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 7 Jul 2017 16:48:18 -0400 Subject: [PATCH] Updated Boost datetime Examples Translated (markdown) --- Boost-datetime-Examples-Translated.md | 74 +++++++++++++-------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/Boost-datetime-Examples-Translated.md b/Boost-datetime-Examples-Translated.md index baa9ce7..4c8ea23 100644 --- a/Boost-datetime-Examples-Translated.md +++ b/Boost-datetime-Examples-Translated.md @@ -27,49 +27,49 @@ look if ported to this library. ### Dates as String +```c++ +#include "date.h" +#include +#include +#include +#include - #include "date.h" - #include - #include - #include - #include - - int - main() +int +main() +{ + using namespace date; + using namespace std; + try { - using namespace date; - using namespace std; - try - { - // The following date is in ISO 8601 extended format (CCYY-MM-DD) - istringstream in{"2001-10-9"}; // 2001-October-09 - year_month_day d; - in >> parse("%F", d); - assert(d.ok()); - cout << format("%Y-%b-%d\n", d); + // The following date is in ISO 8601 extended format (CCYY-MM-DD) + istringstream in{"2001-10-9"}; // 2001-October-09 + year_month_day d; + in >> parse("%F", d); + assert(d.ok()); + cout << format("%Y-%b-%d\n", d); - // Read ISO Standard(CCYYMMDD) and output ISO Extended - in.str("20011009"); // 2001-Oct-09 - in >> parse("%Y%m%d", d); - assert(d.ok()); - cout << d << '\n'; // 2001-10-09 + // Read ISO Standard(CCYYMMDD) and output ISO Extended + in.str("20011009"); // 2001-Oct-09 + in >> parse("%Y%m%d", d); + assert(d.ok()); + cout << d << '\n'; // 2001-10-09 - // Output the parts of the date - Tuesday October 9, 2001 - cout << format("%A %B %e, %Y\n", d); + // Output the parts of the date - Tuesday October 9, 2001 + cout << format("%A %B %e, %Y\n", d); - // Let's send in month 25 by accident and create an exception - in.str("20012509"); // 2001-??-09 - in.exceptions(std::ios::failbit); - cout << "An expected exception is next:\n"; - in >> parse("%Y%m%d", d); - cout << "oh oh, you shouldn't reach this line:\n"; - } - catch (const exception& e) - { - cout << "Exception: " << e.what() << '\n'; - } + // Let's send in month 25 by accident and create an exception + in.str("20012509"); // 2001-??-09 + in.exceptions(std::ios::failbit); + cout << "An expected exception is next:\n"; + in >> parse("%Y%m%d", d); + cout << "oh oh, you shouldn't reach this line:\n"; } - + catch (const exception& e) + { + cout << "Exception: " << e.what() << '\n'; + } +} +``` ### Days Alive