在屏幕上以良好的格式显示时间

display time on the screen with a nice format

本文关键字:格式 显示 时间 屏幕      更新时间:2023-10-16
void clock(int hour, int minute){   
wstringstream wss;
time_t second;
struct tm *current;
current = localtime(&second); // get the running time which is in ms
second = clock()/1000-extra;  //now convert it to second, "extra" is 0 in the start
char buffer[80];
if (second == 60){ 
    setminute(clock() / 1000 / 60);
    i=1;
    extra=extra + 60*(i); 
   //when 60 passed, second will return to 0, i start at 0 in somewhere else;
}
else if (startminute == 60){ sethour(clock() / 1000 / 60 / 60); setminute(0); }
wss << starthour  << " : ";
wss << startminute << " : ";
wss << second << " ";
wss << "AM" << endl;

textToGenerate.append(wss.str());
}

这就是我如何将程序运行时间转换为小时-分钟-秒的格式。我把钟定在凌晨12点开始。在屏幕上看起来像这个12 : 0 : 0 am

我想知道是否有,我可以将格式更改为标准00:00:00 am/pm

您可以将strftime与r%一起使用。请参见此处:http://www.cplusplus.com/reference/ctime/strftime/