QT 85399转HH:MM:sS
时间: 2023-07-29 07:12:21 浏览: 47
以下是将85399转换为HH:MM:SS的C++代码:
```cpp
#include <iostream>
using namespace std;
int main() {
int seconds = 85399;
int hours = seconds / 3600;
int minutes = (seconds % 3600) / 60;
int secs = seconds % 60;
printf("%02d:%02d:%02d", hours, minutes, secs);
return 0;
}
```
输出结果为:23:46:39
相关问题
QT 85399转QString HH:MM:sS
以下是将85399转换为HH:MM:SS的QString代码:
```cpp
#include <QCoreApplication>
#include <QString>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
int seconds = 85399;
int hours = seconds / 3600;
int minutes = (seconds % 3600) / 60;
int secs = seconds % 60;
QString time = QString("%1:%2:%3").arg(hours, 2, 10, QLatin1Char('0'))
.arg(minutes, 2, 10, QLatin1Char('0'))
.arg(secs, 2, 10, QLatin1Char('0'));
qDebug() << time;
return a.exec();
}
```
输出结果为:`"23:46:39"`
QT HH:MM:SS 转longlong
可以使用QTime类的方法来实现QT时间格式转longlong格式,具体代码如下:
```
QTime time = QTime::fromString("HH:MM:SS", "hh:mm:ss");
qint64 milliseconds = QTime(0, 0).msecsTo(time);
```
其中,第一行代码将字符串格式的时间转换为QTime对象,第二行代码使用QTime类的msecsTo方法将时间转换为毫秒数,最终得到的毫秒数即为longlong类型。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)