#include <iostream>
#include <time.h>
#include <boost/date_time/posix_time/posix_time.hpp>
using namespace std;
using namespace boost;
posix_time::ptime
from_string_format (const string& string_time, const char *format)
{
struct tm time_info;
memset(&time_info, 0, sizeof(struct tm));
if (strptime(string_time.c_str(), format, &time_info) == NULL) {
// Return a non date_time ptime object.
return posix_time::ptime(posix_time::not_a_date_time);
}
return posix_time::ptime_from_tm(time_info);
}
int main(int argc, const char *argv[])
{
string ts("2014-03-18T15:09:29.167Z");
std::cout << ts << std::endl;
posix_time::ptime pt(from_string_format(ts, "%FT%T%z"));
return 0;
}