Files
date_time/doc/class_ptime.html
2004-01-20 05:01:34 +00:00

220 lines
8.6 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>posix_time::ptime Documentation</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head>
<body>
<a href="../../../index.htm">
<img align="left" src="../../../c++boost.gif" alt="C++ Boost">
</a>
<h1>posix_time::ptime Documentation</h1>
<p>&nbsp;<p>
<hr>
<a href="index.html">Overall Index</a> --
<a href="gregorian.html">Gregorian Index</a> --
<a href="posix_time.html">Posix Time Index</a>
<p>
<font class="bold">ptime Documentation</font>
<p>
<a href="class_ptime.html#header">Header</a> --
<a href="class_ptime.html#construct">Construction</a> --
<a href="class_ptime.html#constructfromstring">Construct from String</a> --
<a href="class_ptime.html#constructfromclock">Construct from Clock</a> --
<a href="class_ptime.html#constructfromtimet">Construct from time_t</a> --
<a href="class_ptime.html#accessors">Accessors</a> --
<a href="class_ptime.html#conversiontostring">Conversion To String</a> --
<a href="class_ptime.html#operators">Operators</a>
<p>
<h2><a name="intro">Introduction</a></h2>
<p>
The class boost::posix_time::ptime is the primary interface for time
point manipulation. In general, the ptime class is immutable once
constructed although it does allow assignment.
<p>
Class ptime is dependent on <a href="class_date.html">gregorian::date</a>
for the interface to the date portion of a time point.
<p>
Other techniques for creating times include <a href="time_iterators.html">time iterators</a>.
<p>
<p>
<h2><a name="header">Header</a></h2>
<pre>
#include "boost/date_time/posix_time/posix_time.hpp" //include all types plus i/o
or
#include "boost/date_time/posix_time/posix_time_types.hpp" //no i/o just types
</pre>
<p>
<h2><a name="construct">Construction</a></h2>
<p>
<table border=1 cellspacing=3 cellpadding=3>
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
<tr><td class="nowrap">ptime(date,time_duration)</td>
<td>Construct from a date and offset
</td>
<td class="nowrap">ptime t1(date(2002,Jan,10), time_duration(1,2,3));<br>
ptime t2(date(2002,Jan,10), hours(1)+nanosec(5));</td></tr>
<tr><td class="nowrap">ptime(ptime)</td>
<td>Copy constructor</td>
<td class="nowrap">ptime t3(t1)</td></tr>
<tr><td class="nowrap">ptime(special_values sv)</td>
<td>Constructor for infinities, not-a-date-time</td>
<td class="nowrap">ptime t1(neg_infin);<br>
ptime t2(pos_infin);<br>
ptime t3(not_a_date_time);<br>
</td></tr>
</table>
<p>
<h2><a name="constructfromstring">Construction From String</a></h2>
<p>
<table border=1 cellspacing=3 cellpadding=3>
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
<tr><td class="nowrap">ptime <font class="func">time_from_string</font>(const std::string&)</td>
<td>From delimited string.</td>
<td class="nowrap">std::string ts("2002-01-20 23:59:59.000");
<br>
ptime t(time_from_string(ts))</td></tr>
<tr><td class="nowrap">ptime <font class="func">from_iso_string</font>(const std::string&)</td>
<td>From non delimited iso form string.</td>
<td class="nowrap">std::string ts("20020131T235959");
<br>
ptime t(from_iso_string(ts))</td></tr>
</table>
<p>
<h2><a name="constructfromclock">Construction From Clock</a></h2>
<p>
<table border=1 cellspacing=3 cellpadding=3>
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
<tr><td class="nowrap">static ptime second_clock::local_time();</td>
<td>Get the local time, second level resolution, based on the time zone settings of the computer.</td>
<td class="nowrap">ptime t(second_clock::local_time())</td></tr>
<tr><td class="nowrap">static ptime second_clock::universal_time()</td>
<td>Get the UTC time.</td>
<td class="nowrap">ptime t(second_clock::universal_day())</td></tr>
</table>
<p>
<h2><a name="constructfromtimet">Construction From time_t</a></h2>
<p>
<table border=1 cellspacing=3 cellpadding=3>
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
<tr><td>ptime from_time_t(time_t t);</td>
<td>Converts a time_t into a ptime.</td>
<td>ptime t = from_time_t(tt);</td></tr>
</table>
<p>
<h2><a name="accessors">Accessors</a></h2>
<p>
<table border=1 cellspacing=3 cellpadding=3>
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
<tr><td class="nowrap">date <font class="func">date</font>() const</td>
<td>Get the date part of a time.</td>
<td class="nowrap">date d(2002,Jan,10);<br>
ptime t(d, hour(1));<br>
t.date() --> 2002-Jan-10;</td></tr>
<tr><td class="nowrap">time_duration <font class="func">time_of_day</font>() const</td>
<td>Get the time offset in the day.</td>
<td class="nowrap">date d(2002,Jan,10);<br>
ptime t(d, hour(1));<br>
t.time_of_day() --> 01:00:00;</td></tr>
</table>
<p>
<h2><a name="conversiontostring">Conversion To String</a></h2>
<p>
<table border=1 cellspacing=3 cellpadding=3>
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
<tr><td class="nowrap">std::string <font class="func">to_simple_string</font>(ptime)</td>
<td>To YYYY-mmm-DD HH:MM:SS.fffffffff string where mmm 3 char month name. Fractional seconds only included if non-zero.</td>
<td class="nowrap">2002-Jan-01 10:00:01.123456789</td></tr>
<tr><td class="nowrap">std::string <font class="func">to_iso_string</font>(ptime)</td>
<td>Convert to form YYYYMMDDTHHMMSS,fffffffff where T is the date-time separator</td>
<td class="nowrap">20020131T100001,123456789</td></tr>
<tr><td class="nowrap">std::string <font class="func">to_iso_extended_string</font>(ptime)</td>
<td>Convert to form YYYY-MM-DDTHH:MM:SS,fffffffff where T is the date-time separator</td>
<td class="nowrap">2002-01-31T10:00:01,123456789</td></tr>
</table>
<p>
<h2><a name="operators">Operators</a></h2>
<p>
<table border=1 cellspacing=3 cellpadding=3>
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
<tr><td><font class="func">operator&lt;&lt;</font></td>
<td>Stream output operator. Format of the date output is subject to the current
localization settings. See <a href="class_greg_base_facet.html">I/O localization</a>
for more.
</td>
<td class="nowrap">date d(2002,Jan,1)<br>
ptime t(d, hours(3)+minutes(2)+milliseconds(1));<br>
std::cout &lt;&lt; t &lt;&lt; std::endl;//2002-Jan-01 03:02:00.001</td></tr>
<tr><td class="nowrap">operator==, operator!=,<br> operator&gt;, operator&lt;
<br> operator&gt;=, operator&lt;=</td>
<td>A full complement of comparison operators</td>
<td class="nowrap">t1 == t2, etc</td></tr>
<tr><td class="nowrap">ptime <font class="func">operator+</font>(date_duration) const</td>
<td>Return a ptime adding a day offset</td>
<td class="nowrap">date d(2002,Jan,1);<br>
ptime t(d,minutes(5));<br>
date_duration dd(1); <br>
ptime t2 = t + dd;</td></tr>
<tr><td class="nowrap">ptime <font class="func">operator-</font>(date_duration) const</td>
<td>Return a ptime subtracting a day offset</td>
<td class="nowrap">date d(2002,Jan,1);<br>
ptime t(d,minutes(5));<br>
date_duration dd(1); <br>
ptime t2 = t - dd;</td></tr>
<tr><td class="nowrap">ptime <font class="func">operator+</font>(time_duration) const</td>
<td>Return a ptime adding a time duration</td>
<td class="nowrap">date d(2002,Jan,1);<br>
ptime t(d,minutes(5));<br>
ptime t2 = t + hours(1) + minutes(2);</td></tr>
<tr><td class="nowrap">ptime <font class="func">operator-</font>(time_duration) const</td>
<td>Return a ptime subtracting a time duration</td>
<td class="nowrap">date d(2002,Jan,1);<br>
ptime t(d,minutes(5));<br>
ptime t2 = t - minutes(2);</td></tr>
<tr><td class="nowrap">time_duration <font class="func">operator-</font>(ptime) const</td>
<td>Take the difference between two times.</td>
<td class="nowrap">date d(2002,Jan,1);<br>
ptime t1(d,minutes(5));<br>
ptime t2(d,seconds(5));<br>
time_duration t3 = t2 - t1;//negative result</td></tr>
</table>
<p>
<hr>
<address><small>
<!-- hhmts start -->
Last modified: Mon Jan 19 21:49:15 MST 2004
<!-- hhmts end -->
by <a href="mailto:jeff&#64;crystalclearsoftware.com">Jeff Garland</a> &copy; 2000-2002
</small></address>
</body>
</html>