Boost C++ Libraries: Ticket #11813: Microseconds get cut off in ISO string representation if all zero (posix_time::to_iso_string) https://svn.boost.org/trac10/ticket/11813 <pre class="wiki">#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;boost/date_time/posix_time/posix_time.hpp&gt; int main() { boost::posix_time::ptime timestamp = boost::posix_time::microsec_clock::local_time(); std::string sTime( boost::posix_time::to_iso_string( timestamp )); std::cout &lt;&lt; "Timestamp: " &lt;&lt; sTime &lt;&lt; std::endl; return 0; } </pre><p> This outputs for example: <em>Timestamp: 20151121T141522.999982</em> </p> <p> Now, if microseconds are all zero the output I'd expected was<br /> <em>Timestamp: 20151121T141523.000000</em><br /> but actually is<br /> <em>Timestamp: 20151121T141523</em> </p> <p> Now, when trying to cut off the microseconds fraction (for whatever reason) by doing </p> <pre class="wiki">std::string sFraction = sTime.substr( 16, 21 ); </pre><p> you may end up with the following error: </p> <pre class="wiki">Something unexpected happened: 'basic_string::substr: __pos (which is 16) &gt; this-&gt;size() (which is 15)' </pre><p> I saw this behavior in Boost 1.55.0, but when I checked the current sources online, I couldn't see any difference, so I think this would occur in the current version, too. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11813 Trac 1.4.3 viboes Sat, 21 Nov 2015 20:30:32 GMT component changed; owner set https://svn.boost.org/trac10/ticket/11813#comment:1 https://svn.boost.org/trac10/ticket/11813#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">az_sw_dude</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">date_time</span> </li> </ul> Ticket