mirror of
https://github.com/boostorg/date_time.git
synced 2026-01-29 19:32:20 +00:00
60 lines
2.5 KiB
HTML
60 lines
2.5 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
|
|
<title>Example Documentation</title>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css">
|
|
</head><body bgcolor="#ffffff">
|
|
<!-- Generated by Doxygen 1.2.17 -->
|
|
<hr><h1>print_hours.cpp</h1> Demonstrate time iteration, clock retrieval, and simple calculation.
|
|
<p>
|
|
<div class="fragment"><pre><font class="comment">//Print the remaining hours of the day</font>
|
|
<font class="comment">//Uses the clock to get the local time </font>
|
|
<font class="comment">//Use an iterator to iterate over the remaining hours</font>
|
|
<font class="comment">//Retrieve the date part from a time</font>
|
|
<font class="comment">/* Expected Output something like:</font>
|
|
<font class="comment"></font>
|
|
<font class="comment">2002-Mar-08 16:30:59</font>
|
|
<font class="comment">2002-Mar-08 17:30:59</font>
|
|
<font class="comment">2002-Mar-08 18:30:59</font>
|
|
<font class="comment">2002-Mar-08 19:30:59</font>
|
|
<font class="comment">2002-Mar-08 20:30:59</font>
|
|
<font class="comment">2002-Mar-08 21:30:59</font>
|
|
<font class="comment">2002-Mar-08 22:30:59</font>
|
|
<font class="comment">2002-Mar-08 23:30:59</font>
|
|
<font class="comment">Time left till midnight: 07:29:01</font>
|
|
<font class="comment"></font>
|
|
<font class="comment">*/</font>
|
|
|
|
|
|
<font class="preprocessor">#include "boost/date_time/posix_time/posix_time.hpp"</font>
|
|
<font class="preprocessor">#include <iostream></font>
|
|
|
|
|
|
<font class="keywordtype">int</font>
|
|
main()
|
|
{
|
|
<font class="keyword">using</font> <font class="keyword">namespace </font>boost::posix_time;
|
|
using namespace boost::gregorian;
|
|
|
|
<font class="comment">//get the current time from the clock -- one second resolution</font>
|
|
ptime now = second_clock::local_time();
|
|
<font class="comment">//Get the date part out of the time</font>
|
|
date today = now.date();
|
|
date tommorrow = today + date_duration(1);
|
|
ptime tommorrow_start(tommorrow); <font class="comment">//midnight </font>
|
|
|
|
<font class="comment">//iterator adds by one hour</font>
|
|
time_iterator titr(now,hours(1));
|
|
for (; titr < tommorrow_start; ++titr) {
|
|
std::cout << to_simple_string(*titr) << std::endl;
|
|
}
|
|
|
|
time_duration remaining = tommorrow_start - now;
|
|
std::cout << "Time left till midnight: "
|
|
<< to_simple_string(remaining) << std::endl;
|
|
return 0;
|
|
}
|
|
</pre></div><hr><address><small>
|
|
Generated Thu Sep 5 05:52:10 2002 by Doxygen for CrystalClear Software © 2000-2002</small></address>
|
|
</body>
|
|
</html>
|