Add optional format string for stdext::date_time_string() (#1110)

This commit is contained in:
Source61 2020-09-15 18:58:47 +02:00 committed by GitHub
parent 9c1f519f8a
commit 70400bc83e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -45,13 +45,13 @@ std::string resolve_path(const std::string& filePath, std::string sourcePath)
return sourcePath + filePath; return sourcePath + filePath;
} }
std::string date_time_string() std::string date_time_string(const char* format/* = "%b %d %Y %H:%M:%S"*/)
{ {
char date[32]; char date[100];
std::time_t tnow; std::time_t tnow;
std::time(&tnow); std::time(&tnow);
std::tm *ts = std::localtime(&tnow); std::tm *ts = std::localtime(&tnow);
std::strftime(date, 32, "%b %d %Y %H:%M:%S", ts); std::strftime(date, 100, format, ts);
return std::string(date); return std::string(date);
} }

View File

@ -38,7 +38,7 @@ template<typename T> T from_string(const std::string& str, T def = T()) { return
/// Resolve a file path by combining sourcePath with filePath /// Resolve a file path by combining sourcePath with filePath
std::string resolve_path(const std::string& filePath, std::string sourcePath); std::string resolve_path(const std::string& filePath, std::string sourcePath);
/// Get current date and time in a std::string /// Get current date and time in a std::string
std::string date_time_string(); std::string date_time_string(const char* format = "%b %d %Y %H:%M:%S");
std::string dec_to_hex(uint64_t num); std::string dec_to_hex(uint64_t num);
uint64_t hex_to_dec(const std::string& str); uint64_t hex_to_dec(const std::string& str);