If you have a date / time string, you can convert it to a ptime object as follows:
using boost::posix_time; ptime t = time_from_string(datetimeString);
With this, you can easily get time_duration, which contains fractional seconds.
time_duration td = t.time_of_day(); long fs = td.fractional_seconds();
You can also get total milliseconds or microseconds as follows:
long ms = td.total_milliseconds(); long us = td.total_microseconds();
Read more about what you can do in the documentation .
UPDATE
If the input format may be different, so you want to use time_input_facet , you can check time_facet.hpp for the appropriate format. Here is what you probably want to choose from:
static const char_type fractional_seconds_format[3];
UPDATE2
In time_facet.hpp (Boost 1.45) When analyzing, I see the following:
case 'f': { // check for decimal, check special_values if missing if(*sitr == '.') { ++sitr; parse_frac_type(sitr, stream_end, frac); ...
I do not understand why this will require anything but a point between seconds and fractional seconds. Maybe you are using a different version of Boost?
source share