QLocale doesn't match system locale
Solved
General and Desktop
-
I'm using Qt 6.2.1 on Windows 11 with a system locale different from en_US but whatever project I create (Window, Console) if I use a simple code like:
qInfo().nospace() << QDateTime::currentDateTime().toString("dd MMMM yyyy hh:mm:ss.zzz");
It prints the date in english locale
-
Hi,
What is your locale ?
What do you get ?
What do you expect ? -
I found the error. From docs here: https://doc.qt.io/qt-6/qdatetime.html#toString it is reported
Note: Day and month names as well as AM/PM indication are given in English (C locale). If localized month and day names and localized forms of AM/PM are used, use QLocale::system().toDateTime().
Correct way to use system locale or a desired locale is
qInfo().nospace() << QLocale::system().toString(QDateTime::currentDateTime(), "dd MMMM yyyy hh:mm:ss.zzz");