Date Time in qml



  • Hi friends,
    I need to print date and time in qml.I could do that bt nt as i required..Here i expalin u ..

    I need to print date in dd_MM_yyyy(ie.. underscore format).I could not get this work..However i give the format ,independent of that it is printing as dd/MM/yyyy. Here is my code.

    @ QtObject {
    id: dateObj
    property var locale: Qt.locale()
    property date currentDate: new Date()
    property string dateString
    }
    X_onClicked {
    dateObj.dateString = dateObj.currentDate.toLocaleString("MM-dd-yyyy")
    }@

    If anyone Knows,please help me...
    Thanks in advance


  • Moderators

    Hi,

    "toLocaleString":http://qt-project.org/doc/qt-5/qml-qtqml-date.html#toLocaleString-method expects locale as first argument so just pass Qt.locale()
    eg.
    @
    Text {
    text :new Date().toLocaleString(Qt.locale(),"MM-dd-yyyy");
    }
    @



  • thanks p3c0..Its working nw..:-)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.