Boost logo

Boost Users :

Subject: [Boost-users] date_time question
From: Amadeus W.M. (amadeus84_at_[hidden])
Date: 2009-05-22 21:36:38

I have a file with tab separated entries like this:

1230735660 12/31/2008 10:01:00 8.94 277880
1230735729 12/31/2008 10:02:09 8.95 279693
1230735791 12/31/2008 10:03:11 8.95 284743


I don't assume which column represents the date so I read one line at the
time and test each token if it's a date in the format "%m/%d/%Y %H:%M:%S".

However, when I process the first token (1230735660) date_time thinks it's
a date in my format and returns

5660-Dec-07 00:00:00

How come? It seems to think that 3 is a separator. Could anyone please
shed some light? Thanks!

Here is a short program that exemplifies the problem:

// g++ -g -Wall -o dateIO -I/usr/local/include/boost-1_38 -L/usr/local/
lib/ dateIOTest.C -lboost_date_time-gcc43-mt-1_38

#include <iostream>
#include <sstream>
#include <cstdlib>
#include <string>
#include <boost/date_time/posix_time/posix_time.hpp>

using namespace std;
using namespace boost::posix_time;

int main(int argc, char * argv[])
    ptime pt;
    string datestr("1230735660");
    istringstream INSTR(datestr);
    time_input_facet * tifacet=new time_input_facet("%m/%d/%Y %H:%M:%S");
    locale loc(INSTR.getloc(),tifacet);
    INSTR >> pt;

    cout << pt << endl;

    return 0;

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at