qtqtranslateqt5.7

How to translate dates in QT?


I would like to make a label with the date written on it in many languages. How can I translate it from english to the choosen language? Like this:

English:Thursday, 1 January 1970

Arabic:۱۹۷۰ الخميس, ۱ يناير

The code I used to get the date is:

QLabel *Time = new QLabel(QDate::currentDate().toString(Qt::SystemLocaleLongDate));

Solution

  • You should use QLocale in order to convert a QDate to string.
    This could be acheived like this :

        QLocale locale = QLocale(QLocale::Arabic, QLocale::Egypt);
        QString arabicDate = locale.toString(QDate::currentDate());