Qt秒到DD HH SS [英] Qt seconds to DD HH SS
本文介绍了Qt秒到DD HH SS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Qt 4.8如何以DD HH SS格式打印时间?我有秒钟,我想找回这种格式的字符串。
using Qt 4.8 how can I print the time in the format DD HH SS? I have the seconds and I want to get back a string in that format.
推荐答案
QDateTime::fromTime_t(seconds).toString("ss hh DD");
请参见 http://qt-project.org/doc/qt-5.0/qdatetime.html#toString
如果您想要持续时间(您的问题还不清楚),请尝试以下操作:
If you want a duration ( your question was really unclear) try something like :
QString seconds_to_DHMS(quint32 duration)
{
QString res;
int seconds = (int) (duration % 60);
duration /= 60;
int minutes = (int) (duration % 60);
duration /= 60;
int hours = (int) (duration % 24);
int days = (int) (duration / 24);
if((hours == 0)&&(days == 0))
return res.sprintf("%02d:%02d", minutes, seconds);
if (days == 0)
return res.sprintf("%02d:%02d:%02d", hours, minutes, seconds);
return res.sprintf("%dd%02d:%02d:%02d", days, hours, minutes, seconds);
}
这篇关于Qt秒到DD HH SS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文