mirror of
https://github.com/boostorg/date_time.git
synced 2026-02-24 16:02:26 +00:00
316 lines
8.7 KiB
XML
316 lines
8.7 KiB
XML
<section id="date_time.posix_time.ptime_class">
|
|
<title>Ptime Class</title>
|
|
|
|
<link linkend="ptime_intro">Introduction</link> --
|
|
<link linkend="ptime_header">Header</link> --
|
|
<link linkend="ptime_constr">Construction</link> --
|
|
<link linkend="ptime_from_string">Construct from String</link> --
|
|
<link linkend="ptime_from_clock">Construct from Clock</link> --
|
|
<link linkend="ptime_from_time_t">Construct from time_t</link> --
|
|
<link linkend="ptime_accessors">Accessors</link> --
|
|
<link linkend="ptime_to_string">Conversion To String</link> --
|
|
<link linkend="ptime_operators">Operators</link>
|
|
|
|
<anchor id="ptime_intro" />
|
|
<bridgehead renderas="sect3">Introduction</bridgehead>
|
|
<para>
|
|
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.
|
|
</para>
|
|
<para>
|
|
Class ptime is dependent on <link linkend="date_time.gregorian.date_class">gregorian::date</link> for the interface to the date portion of a time point.
|
|
</para>
|
|
<para>
|
|
Other techniques for creating times include <link linkend="date_time.posix_time.time_iterators">time iterators</link>.
|
|
</para>
|
|
|
|
<anchor id="ptime_header" />
|
|
<bridgehead renderas="sect3">Header</bridgehead>
|
|
<para>
|
|
<programlisting>
|
|
#include "boost/date_time/gregorian/gregorian.hpp" //include all types plus i/o
|
|
or
|
|
#include "boost/date_time/gregorian/gregorian_types.hpp" //no i/o just types
|
|
</programlisting>
|
|
</para>
|
|
|
|
<anchor id="ptime_constr" />
|
|
<bridgehead renderas="sect3">Construction</bridgehead>
|
|
<para>
|
|
<informaltable frame="all">
|
|
<tgroup cols="3">
|
|
<thead>
|
|
<row>
|
|
<entry>Syntax</entry>
|
|
<entry>Description</entry>
|
|
<entry>Example</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>ptime(date,time_duration)</entry>
|
|
<entry>Construct from a date and offset</entry>
|
|
<entry>
|
|
ptime t1(date(2002,Jan,10), time_duration(1,2,3));
|
|
ptime t2(date(2002,Jan,10), hours(1)+nanosec(5));
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>ptime(ptime)</entry>
|
|
<entry>Copy constructor</entry>
|
|
<entry>ptime t3(t1)</entry>
|
|
</row>
|
|
<row>
|
|
<entry>ptime(special_values sv)</entry>
|
|
<entry>Constructor for infinities, not-a-date-time, max_date_time, and min_date_time</entry>
|
|
<entry>
|
|
ptime d1(neg_infin);
|
|
ptime d2(pos_infin);
|
|
ptime d3(not_a_date_time);
|
|
ptime d4(max_date_time);
|
|
ptime d5(min_date_time);</entry>
|
|
</row>
|
|
<row>
|
|
<entry>ptime;</entry>
|
|
<entry>Default constructor. Creates a ptime object initialized to not_a_date_time. NOTE: this constructor can be disabled by defining DATE_TIME_NO_DEFAULT_CONSTRUCTOR (see compiler_config.hpp)</entry>
|
|
<entry>ptime p; // p => not_a_date_time</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
|
|
|
|
<anchor id="ptime_from_string" />
|
|
<bridgehead renderas="sect3">Construct from String</bridgehead>
|
|
<para>
|
|
<informaltable frame="all">
|
|
<tgroup cols="3">
|
|
<thead>
|
|
<row>
|
|
<entry>Syntax</entry>
|
|
<entry>Description</entry>
|
|
<entry>Example</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>ptime time_from_string(const std::string&)</entry>
|
|
<entry>From delimited string.</entry>
|
|
<entry>std::string ts("2002-01-20 23:59:59.000");
|
|
ptime t(time_from_string(ts))</entry>
|
|
</row>
|
|
<row>
|
|
<entry>ptime from_iso_string(const std::string&)</entry>
|
|
<entry>From non delimited iso form string.</entry>
|
|
<entry>std::string ts("20020131T235959");
|
|
ptime t(from_iso_string(ts))</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
|
|
|
|
<anchor id="ptime_from_clock" />
|
|
<bridgehead renderas="sect3">Construct from Clock</bridgehead>
|
|
<para>
|
|
<informaltable frame="all">
|
|
<tgroup cols="3">
|
|
<thead>
|
|
<row>
|
|
<entry>Syntax</entry>
|
|
<entry>Description</entry>
|
|
<entry>Example</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>static ptime second_clock::local_time();</entry>
|
|
<entry>Get the local time, second level resolution, based on the time zone settings of the computer.</entry>
|
|
<entry>ptime t(second_clock::local_time())</entry>
|
|
</row>
|
|
<row>
|
|
<entry>static ptime second_clock::universal_time()</entry>
|
|
<entry>Get the UTC time.</entry>
|
|
<entry>ptime t(second_clock::universal_day())</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
|
|
|
|
<anchor id="ptime_from_time_t" />
|
|
<bridgehead renderas="sect3">Construct from time_t</bridgehead>
|
|
<para>
|
|
<informaltable frame="all">
|
|
<tgroup cols="3">
|
|
<thead>
|
|
<row>
|
|
<entry>Syntax</entry>
|
|
<entry>Description</entry>
|
|
<entry>Example</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>ptime from_time_t(time_t t);</entry>
|
|
<entry>Converts a time_t into a ptime.</entry>
|
|
<entry>ptime t = from_time_t(tt);</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
|
|
|
|
<anchor id="ptime_accessors" />
|
|
<bridgehead renderas="sect3">Accessors</bridgehead>
|
|
<para>
|
|
<informaltable frame="all">
|
|
<tgroup cols="3">
|
|
<thead>
|
|
<row>
|
|
<entry>Syntax</entry>
|
|
<entry>Description</entry>
|
|
<entry>Example</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>date date() const</entry>
|
|
<entry>Get the date part of a time.</entry>
|
|
<entry>
|
|
date d(2002,Jan,10);
|
|
ptime t(d, hour(1));
|
|
t.date() --> 2002-Jan-10;
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>time_duration time_of_day() const</entry>
|
|
<entry>Get the time offset in the day.</entry>
|
|
<entry>
|
|
date d(2002,Jan,10);
|
|
ptime t(d, hour(1));
|
|
t.time_of_day() --> 01:00:00;
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
|
|
|
|
<anchor id="ptime_to_string" />
|
|
<bridgehead renderas="sect3">Conversion to String</bridgehead>
|
|
<para>
|
|
<informaltable frame="all">
|
|
<tgroup cols="3">
|
|
<thead>
|
|
<row>
|
|
<entry>Syntax</entry>
|
|
<entry>Description</entry>
|
|
<entry>Example</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>std::string to_simple_string(ptime)</entry>
|
|
<entry>To YYYY-mmm-DD HH:MM:SS.fffffffff string where mmm 3 char month name. Fractional seconds only included if non-zero.</entry>
|
|
<entry>2002-Jan-01 10:00:01.123456789</entry>
|
|
</row>
|
|
<row>
|
|
<entry>std::string to_iso_string(ptime)</entry>
|
|
<entry>Convert to form YYYYMMDDTHHMMSS,fffffffff where T is the date-time separator</entry>
|
|
<entry>20020131T100001,123456789</entry>
|
|
</row>
|
|
<row>
|
|
<entry>std::string to_iso_extended_string(ptime)</entry>
|
|
<entry>Convert to form YYYY-MM-DDTHH:MM:SS,fffffffff where T is the date-time separator</entry>
|
|
<entry>2002-01-31T10:00:01,123456789</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
|
|
|
|
<anchor id="ptime_operators" />
|
|
<bridgehead renderas="sect3">Operators</bridgehead>
|
|
<para>
|
|
<informaltable frame="all">
|
|
<tgroup cols="3">
|
|
<thead>
|
|
<row>
|
|
<entry>Syntax</entry>
|
|
<entry>Description</entry>
|
|
<entry>Example</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>
|
|
operator==, operator!=,
|
|
operator>, operator<
|
|
operator>=, operator<=
|
|
</entry>
|
|
<entry>A full complement of comparison operators</entry>
|
|
<entry>t1 == t2, etc</entry>
|
|
</row>
|
|
<row>
|
|
<entry>ptime operator+(date_duration) const</entry>
|
|
<entry>Return a ptime adding a day offset</entry>
|
|
<entry>
|
|
date d(2002,Jan,1);
|
|
ptime t(d,minutes(5));
|
|
date_duration dd(1);
|
|
ptime t2 = t + dd;
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>ptime operator-(date_duration) const</entry>
|
|
<entry>Return a ptime subtracting a day offset</entry>
|
|
<entry>
|
|
date d(2002,Jan,1);
|
|
ptime t(d,minutes(5));
|
|
date_duration dd(1);
|
|
ptime t2 = t - dd;
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>ptime operator+(time_duration) const</entry>
|
|
<entry>Return a ptime adding a time duration</entry>
|
|
<entry>
|
|
date d(2002,Jan,1);
|
|
ptime t(d,minutes(5));
|
|
ptime t2 = t + hours(1) + minutes(2);
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>ptime operator-(time_duration) const</entry>
|
|
<entry>Return a ptime subtracting a time duration</entry>
|
|
<entry>
|
|
date d(2002,Jan,1);
|
|
ptime t(d,minutes(5));
|
|
ptime t2 = t - minutes(2);
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>time_duration operator-(ptime) const</entry>
|
|
<entry>Take the difference between two times.</entry>
|
|
<entry>
|
|
date d(2002,Jan,1);
|
|
ptime t1(d,minutes(5));
|
|
ptime t2(d,seconds(5));
|
|
time_duration t3 = t2 - t1;//negative result
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
|
|
|
|
<link linkend="top">top</link>
|
|
</section>
|