Created
February 19, 2015 13:55
-
-
Save alepez/537ab5ea93fdcf529776 to your computer and use it in GitHub Desktop.
format any time template
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
inline std::string formatTime(const time_t t) { | |
std::tm timeinfo = *::gmtime(&t); | |
char buffer[16]; | |
std::strftime(buffer, sizeof(buffer), "%Y%m%d-%H%M%S", &timeinfo); | |
return std::string { buffer }; | |
} | |
template <typename T> | |
inline std::string formatTime(T&& t) { | |
using clock = typename std::remove_reference<T>::type::clock; | |
return formatTime(clock::to_time_t(t)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment