以漂亮的格式在屏幕上显示时间

时间:2014-04-13 05:46:00

标签: c++ time formatting

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:00开始设置时钟。它在屏幕上看起来像12 : 0 : 0 am

我想知道无论如何我可以将格式更改为标准00:00:00上午/下午

1 个答案:

答案 0 :(得分:0)

您可以将strftime与r%一起使用。见这里:http://www.cplusplus.com/reference/ctime/strftime/