Boost logo

Boost Users :

Subject: [Boost-users] Boost Date/Time
From: asif saeed (asif.lse2_at_[hidden])
Date: 2012-02-13 06:01:21


I get a run-time error when I run the following code;

std::string LocaleFormattedDateTime (::boost::posix_time::ptime pt)
  std::string s;
  std::ostringstream ss;

  //::boost::posix_time::time_facet * tf = new
  ::boost::posix_time::time_facet tf;
  //std::locale custom_locale (std::locale(""), tf);
  std::locale custom_locale (std::locale(""), &tf);

  // custom_locale takes ownership of the tf facet
  ss.imbue (custom_locale);
  //(*tf).format("%Y%m%d-%H%M%S-%f"); // date time
  tf.format("%Y%m%d-%H%M%S-%f"); // date time
  ss << pt;
  // don't explicitly delete tf - what's wrong with a stack variable? why
this runtime error? What is the point of new() above and
                                     //what if I don't delete allocated
memory here.
  return ss.str();

void CurrentDateTimeWithMicroseconds(char s[], int sz = 100)
using namespace boost::posix_time;
using namespace std;
using boost::date_time::date_facet;

ptime t = microsec_clock::local_time();
ostringstream ss;
//time_facet *df = new time_facet();
time_facet df;
//std::locale loc (std::locale(""), df);
std::locale loc (std::locale(""), &df);
ss << LocaleFormattedDateTime(t) ;

Can you tell me the problem?

I modified this code after copying this from some online source.

Thanks in advance, Asif

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