Created
April 24, 2011 05:35
-
-
Save sansumbrella/939345 to your computer and use it in GitHub Desktop.
A sane way to format dates from boost. Simple interface, no noodling with stringstreams and locales.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// DateUtils.cpp | |
// Created by David Wicks on 4/23/11. | |
#include "DateUtils.h" | |
#include <sstream> | |
using namespace boost::gregorian; | |
using namespace std; | |
string DateUtils::formatDate( const date& d, const string& fmt ) | |
{ | |
date_facet* facet( new date_facet() ); | |
facet->format( fmt.c_str() ); | |
stringstream ss; | |
ss.imbue( locale( locale::classic(), facet ) ); | |
ss << d; | |
return ss.str(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// DateUtils.h | |
// Created by David Wicks on 4/23/11. | |
// | |
#pragma once | |
#include <boost/date_time/gregorian/gregorian.hpp> | |
struct DateUtils | |
{ | |
static std::string formatDate( const boost::gregorian::date& d, const std::string& fmt ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment