Given this is a basic question, I imagine there might be duplicates, but I could not find any. I simply want to get the current iso_date ( like 20110503 ) from boost.
Any pointers ?
I assume you're looking for a Boost.Date_Time-based solution?
#include <locale>
#include <string>
#include <iostream>
#include <sstream>
#include <boost/date_time/gregorian/gregorian.hpp>
std::string utc_date()
{
namespace bg = boost::gregorian;
static char const* const fmt = "%Y%m%d";
std::ostringstream ss;
// assumes std::cout's locale has been set appropriately for the entire app
ss.imbue(std::locale(std::cout.getloc(), new bg::date_facet(fmt)));
ss << bg::day_clock::universal_day();
return ss.str();
}
See Date Time Input/Output for more information on the available format flags.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With