QT重新格式化日期时间字符串

时间:2014-03-18 08:31:18

标签: c++ qt

我的QString包含以下格式的日期:

  

2014-03-18 09:30:36

如何将其格式化为:HH:mm

2 个答案:

答案 0 :(得分:7)

您可以使用QDateTime::fromStringQDateTime::toString方法:

QString dateStr = "2014-03-18 09:30:36";
QString fmt = "yyyy-MM-dd hh:mm:ss";
QDateTime dt = QDateTime::fromString(dateStr, fmt);
QString timeStr = dt.toString("hh:mm");

答案 1 :(得分:-1)

function todayDate(){
    var months = [ "jan", "feb", "mar", "apr", "may", "jun",
       "jul", "aug", "sep", "oct", "nov", "dec" ];
    var today = new Date();
    var dd = today.getDate();
    var mm = today.getMonth();

    var yyyy = today.getFullYear();
    if(dd<10){
        dd='0'+dd;
    }
    if(mm<10){
        mm='0'+mm;
    }
    var today = dd+months[mm]+yyyy;
    console.log("Date::::::::::::::::"+today)
}

我希望我的这个功能有帮助!!