Important: Please read the Qt Code of Conduct -

Date formatting with Translations.

  • I'm trying to make a translatable date string. In "en" languages the date will be displayed "MM/dd/yyyy" and in others it will be displayed as "dd/MM/yyyy".

    I currently use this to translate the date string:

    dateTime.toLocaleDateString(Qt.locale("en_EN"), "MM/dd/yyyy").

    I've added it to the translations by turning it into this:


    How can I make it show as "dd/MM/yyyy"? If I specify

    qsTr("%1").arg(dateTime.toLocaleDateString(Qt.locale(), "MM/dd/yyyy"))

    The output is always in that format, even in English. How can I get simply MM/dd/yyyy while being translatable?