How to format a datetime to string using boost?

后端 未结 2 1178

I want to format a date/time to a string using boost.

Starting with the current date/time:

ptime now = second_clock::universal_time();
2条回答
  •  醉酒成梦
    2020-12-05 14:40

    // create your date
    boost::gregorian::date d(2009, 1, 7); 
    
    // create your formatting
    boost::gregorian::date_facet *df = new boost::gregorian::date_facet("%Y%m%d_%H%M%S"); 
    
    // set your formatting
    ostringstream is;
    is.imbue(std::locale(is.getloc(), df));
    is << d << endl;
    
    // get string
    cout << "output :" << is.str() << endl;
    

提交回复
热议问题