Last active
August 17, 2023 09:42
-
-
Save CaptainJH/11208867 to your computer and use it in GitHub Desktop.
Output date string in C++
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
/// iterate from fromD(like "2014-04-02") to toD("2014-05-02") | |
std::string tpStr = fromD; | |
do { | |
//std::cout << tpStr << std::endl; | |
ParseIntoUserInfoDB(tpStr, root, order); | |
std::tm tm; | |
std::stringstream ss(tpStr + " 0:0:1"); | |
ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S"); | |
auto tp = std::chrono::system_clock::from_time_t(std::mktime(&tm)); | |
tp += std::chrono::hours(24); | |
auto in_time_t = std::chrono::system_clock::to_time_t(tp); | |
std::stringstream ssTp; | |
ssTp << std::put_time(std::localtime(&in_time_t), "%Y-%m-%d"); | |
tpStr = ssTp.str(); | |
} while (tpStr != toD); |
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
#include <string> | |
#include <sstream> | |
#include <chrono> | |
#include <iomanip> | |
std::string GetDate(const char* argv) | |
{ | |
std::string arg(argv); | |
if (pystring::lower(arg) == "today") | |
{ | |
auto now = std::chrono::system_clock::now(); | |
auto in_time_t = std::chrono::system_clock::to_time_t(now); | |
std::stringstream ss; | |
ss << std::put_time(std::localtime(&in_time_t), "%Y-%m-%d"); | |
return ss.str(); | |
} | |
return arg; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment