Qt 计时时间显示

QString getTimeFromSec(int sec)
{
    if(sec<0) return "0:0:0";
    int second = sec%60;
    int min    = (sec/60)%60;
    int hour   = sec/3600;

    QString str = QString("%1:%2:%3").arg(hour).arg(min).arg(second);
    return str;
}

int getSecFromTime(QString time)
{
    QStringList strList = time.split(":");
    if(strList.size() != 3) return 0;
    int second = strList[2].toInt();
    int min    = strList[1].toInt();
    int hh     = strList[0].toInt();
    return (hh*3600+min*60+second);
}
posted @ 2020-11-18 08:31  eric_zw  阅读(763)  评论(0编辑  收藏  举报