在屏幕上以良好的格式显示时间
display time on the screen with a nice format
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/
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 如何在openssl-ecc中获取十六进制格式的私钥
- 当使用比格式支持的精度更高的精度来显示数字时,会写出什么数据
- 将信息输入到下面显示的结构向量中的正确语法/格式是什么
- C++ 我的开关格式中的循环不允许我显示菜单选项或接受输入?
- 如何从文件中读取并将内容存储在动态 2D 数组中并以网格格式显示
- 如何设置数字格式以显示C 中的所有小数位数
- 如何以某种格式为用户显示对象向量
- C++显示具有与.bmp格式不同的 SDL2 的图像
- 在编译时以 static_assert() 格式显示整数
- QT显示双重号码,没有指数格式
- 在图片框中显示cv::Mat格式的网络摄像头提要
- 以C++格式全精度显示浮点数
- 如何不仅要求动态2D阵列的行数和列数,还要求以表格格式显示
- fstream以txt格式显示所有文本
- QTextEdit显示的块中图像后的文本格式
- 使用'uxxxx'格式定义的字符显示错误的字符
- 在屏幕上以良好的格式显示时间
- 在 cout 中将数字十进制格式显示为指数