Files
date_time/doc/exp-time_math.html
2002-09-05 17:17:25 +00:00

41 lines
1.8 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>time_math.cpp</h1> Various types of calculations with times and time durations.
<p>
<div class="fragment"><pre><font class="comment">//Some simple examples of constructing and calculating with times</font>
<font class="comment">//Output:</font>
<font class="comment">//2002-Feb-01 00:00:00 - 2002-Feb-01 05:04:02.001000000 = -5:04:02.001000000</font>
<font class="preprocessor">#include "boost/date_time/posix_time/posix_time.hpp"</font>
<font class="preprocessor">#include &lt;iostream&gt;</font>
<font class="keywordtype">int</font>
main()
{
<font class="keyword">using</font> <font class="keyword">namespace </font>boost::posix_time;
using namespace boost::gregorian;
date d(2002,Feb,1); <font class="comment">//an arbitrary date</font>
<font class="comment">//construct a time by adding up some durations durations</font>
ptime t1(d, hours(5)+minutes(4)+seconds(2)+millisec(1));
<font class="comment">//construct a new time by subtracting some times</font>
ptime t2 = t1 - hours(5)- minutes(4)- seconds(2)- millisec(1);
<font class="comment">//construct a duration by taking the difference between times</font>
time_duration td = t2 - t1;
std::cout &lt;&lt; to_simple_string(t2) &lt;&lt; " - "
&lt;&lt; to_simple_string(t1) &lt;&lt; " = "
&lt;&lt; to_simple_string(td) &lt;&lt; std::endl;
return 0;
}
</pre></div><hr><address><small>
Generated Wed Aug 21 16:54:33 2002 by Doxygen for CrystalClear Software&nbsp;&copy 2000-2002</small></address>
</body>
</html>