0

In my function below I am using the system clock/time to create various strings. Is there a way to make my code stay in 24 hr mode?

This way if the time is in the afternoon my string will start with PM.

string TODO::timeID() 
{
    List l;
    size_t pos = 0;
    string token;
    string d1 = ":";
    string d2 = " ";
    string t1;
    string t2;
    string t3;
    string a;
    int sec;
    string x;
    string y;
    chrono::system_clock::time_point p = chrono::system_clock::now();
    time_t t = chrono::system_clock::to_time_t(p);
    char str[26];
    ctime_s(str, sizeof str, &t);
    string time(str);
    t1 = time.substr(11, 15);
    while ((pos = t1.find(d2)) != std::string::npos) {
        token = t1.substr(0, pos);
        a = token.substr(6, 7);
        token.erase(5,8);
        while ((pos = token.find(d1)) != std::string::npos) {
            t2 = token.substr(0,pos);
            t3 = token.substr(pos);
            t3.erase(0,1);
            x = t2;
            y = t3;
            if (stoi(x) < 12) {
                l.timeID = "AM" + x + y + a;
                return l.timeID;
            }
            else {
                l.timeID = "PM" + x + y + a;
                return l.timeID;
            }
            
        }
        
    }
}

0 Answers0