On Sat, 12 Nov 2005 06:00:17 -0700, Bart wrote
On Fri, 11 Nov 2005 10:37:09 -0700, Sean Rohead wrote:
I am trying to parse ISO datetime strings with millisecond resolution and the fractional seconds are being truncated. Am I doing something wrong in the following code?
Thanks,
Sean Rohead
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include <string> #include "boost/date_time/posix_time/posix_time.hpp"
using namespace std; using namespace boost::posix_time;
void main() { string dateString1 = "20051004T151801"; string dateString2 = "20051004T151801.123"; ptime timestamp1(from_iso_string(dateString1)); ptime timestamp2(from_iso_string(dateString2)); cout << timestamp1 << endl; cout << timestamp2 << endl; }
This code worked as expected for me: 2005-Oct-04 15:18:01 2005-Oct-04 15:18:01.123000
Which version of date_time are you using?
Just to add to this, you'll find the following in the change log documentation for 1.32. to 1.33: The from_iso_string function failed to parse fractional digits. We added code that correctly parses when input has more digits, or too few digits, that the compiled library precision. Ptimes with only a decimal are also correctly parsed. http://www.boost.org/doc/html/date_time/details.html#date_time.changes Jeff