1 <?xml version=
"1.0" encoding=
"utf-8"?>
2 <!DOCTYPE library PUBLIC
"-//Boost//DTD BoostBook XML V1.0//EN"
3 "../../../tools/boostbook/dtd/boostbook.dtd">
5 <!-- Copyright (c) 2001-2004 CrystalClear Software, Inc.
6 Subject to the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
10 <section id=
"date_time.examples.print_month">
11 <title>Print Month
</title>
14 Simple utility to print out days of the month with the days of a month. Demontstrates date iteration (date_time::date_itr).
18 /* This example prints all the dates in a month. It demonstrates
19 * the use of iterators as well as functions of the gregorian_calendar
23 * Enter Month(
1.
.12):
2
33 #include
"boost/date_time/gregorian/gregorian.hpp"
39 std::cout <<
"Enter Year: ";
42 std::cout <<
"Enter Month(1..12): ";
45 using namespace boost::gregorian;
47 //Use the calendar to get the last day of the month
48 int eom_day = gregorian_calendar::end_of_month_day(year,month);
49 date endOfMonth(year,month,eom_day);
51 //construct an iterator starting with firt day of the month
52 day_iterator ditr(date(year,month,
1));
53 //loop thru the days and print each one
54 for (; ditr <= endOfMonth; ++ditr) {
55 #if defined(BOOST_DATE_TIME_NO_LOCALE)
56 std::cout << to_simple_string(*ditr) <<
" ["
58 std::cout << *ditr <<
" ["
60 << ditr-
>day_of_week() <<
"]"
64 catch(std::exception& e) {
66 std::cout <<
"Error bad date, check your entry: \n"
67 <<
" Details: " << e.what() << std::endl;