mirror of
https://github.com/boostorg/date_time.git
synced 2026-01-29 19:32:20 +00:00
71 lines
3.0 KiB
HTML
71 lines
3.0 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<title>Example Documentation</title><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css">
|
|
</head>
|
|
<body bgcolor="#ffffff"> <!-- Generated by Doxygen 1.2.17 -->
|
|
<hr>
|
|
<h1>print_month.cpp</h1>
|
|
Simple utility to print out days of the month with the days of a month.
|
|
Demontstrates date iteration (date_time::date_itr).
|
|
<p></p>
|
|
<div class="fragment" id="DIV1"><pre><font class="comment">/*</font>
|
|
<font class="comment">This example prints all the dates in a month. It demonstrates</font>
|
|
<font class="comment">the use of iterators as well as functions of the gregorian_calendar</font>
|
|
<font class="comment"></font>
|
|
<font class="comment">Output:</font>
|
|
<font class="comment">Enter Year: 2002</font>
|
|
<font class="comment">Enter Month(1..12): 2</font>
|
|
<font class="comment">2002-Feb-01 [Fri]</font>
|
|
<font class="comment">2002-Feb-02 [Sat]</font>
|
|
<font class="comment">2002-Feb-03 [Sun]</font>
|
|
<font class="comment">2002-Feb-04 [Mon]</font>
|
|
<font class="comment">2002-Feb-05 [Tue]</font>
|
|
<font class="comment">2002-Feb-06 [Wed]</font>
|
|
<font class="comment">2002-Feb-07 [Thu]</font>
|
|
<font class="comment">*/</font>
|
|
|
|
<font class="preprocessor">#include "boost/date_time/gregorian/gregorian.hpp"</font>
|
|
<font class="preprocessor">#include <iostream></font>
|
|
|
|
<font class="keywordtype">int</font>
|
|
main()
|
|
{
|
|
std::cout << <font class="stringliteral">"Enter Year: "</font>;
|
|
<font class="keywordtype">int</font> year, month;
|
|
std::cin >> year;
|
|
std::cout << <font class="stringliteral">"Enter Month(1..12): "</font>;
|
|
std::cin >> month;
|
|
|
|
<font class="keyword">using</font> <font class="keyword">namespace </font>boost::gregorian;
|
|
try {
|
|
<font class="comment">//Use the calendar to get the last day of the month</font>
|
|
<font class="keywordtype">int</font> eom_day = gregorian_calendar::end_of_month_day(year,month);
|
|
date endOfMonth(year,month,eom_day);
|
|
|
|
<font class="comment">//construct an iterator starting with first day of the month</font>
|
|
day_iterator ditr(date(year,month,1));
|
|
<font class="comment">//loop thru the days and print each one</font>
|
|
<font class="keywordflow">for</font> (; ditr <= endOfMonth; ++ditr) {
|
|
std::cout << *ditr << <font class="stringliteral">" ["</font>
|
|
<< ditr->day_of_week() << <font class="stringliteral">"]"</font>
|
|
<< std::endl;
|
|
}
|
|
}
|
|
<font class="keywordflow">catch</font>(std::exception& e) {
|
|
|
|
std::cout << <font class="stringliteral">"Error bad date, check your entry: \n"</font>
|
|
<< <font class="stringliteral">" Details: "</font> << e.what() << std::endl;
|
|
}
|
|
<font class="keywordflow">return</font> 0;
|
|
}
|
|
</pre>
|
|
</div>
|
|
<hr>
|
|
<address><small> Generated Wed Aug 21 16:54:33 2002 by Doxygen for CrystalClear
|
|
Software © 2000-2002</small></address>
|
|
</body>
|
|
</html>
|
|
|