#include <ctime>
std::string myTime = "1438";
time_t now = time(0);
struct tm* now_tm = localtime(&now);
now_tm->tm_hour = atoi(myTime.substr(0, 2).c_str());
now_tm->tm_min = atoi(myTime.substr(2, 2).c_str());
now_tm->tm_sec = 0;
time_t target = mktime(now_tm);
char timestamp[32] = "";
strftime(timestamp, 32, "%b %d %Y %I:%M:%S 000 %p", gmtime(&target));
std::cout << timestamp << std::endl;
|