Skip to content

Instantly share code, notes, and snippets.

@alepez
Created February 19, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alepez/537ab5ea93fdcf529776 to your computer and use it in GitHub Desktop.
Save alepez/537ab5ea93fdcf529776 to your computer and use it in GitHub Desktop.
format any time template
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