QDateTime::currentDateTime() sometimes return ???
-
wrote on 1 Oct 2019, 06:47 last edited by asmant 10 Jan 2019, 06:48
Hello, in my windows app's logs I get current date-time like this:
QDateTime dateTime = dateTime.currentDateTime(); QString currentDateTime = dateTime.toString("yyyy-MM-dd HHmmss");
It worked well until I noticed that sometimes the time is ????-??-?? ??:??:??. How it can be that way? I know that windows time can be incorrect, but it should return incorrect time and not ???
-
Hello, in my windows app's logs I get current date-time like this:
QDateTime dateTime = dateTime.currentDateTime(); QString currentDateTime = dateTime.toString("yyyy-MM-dd HHmmss");
It worked well until I noticed that sometimes the time is ????-??-?? ??:??:??. How it can be that way? I know that windows time can be incorrect, but it should return incorrect time and not ???
@asmant How do you write currentDateTime to the log?
-
wrote on 14 Oct 2019, 10:40 last edited by
So, I find out that, for example if the windows language is Egypt(arabic) so the time & date is displayed not in english numbers. It is in Egypt(arabic) writing. Is there a function to get (format) time & date in English language numbers?
-
So, I find out that, for example if the windows language is Egypt(arabic) so the time & date is displayed not in english numbers. It is in Egypt(arabic) writing. Is there a function to get (format) time & date in English language numbers?
@asmant
That's what QLocale is for :) -
@asmant
That's what QLocale is for :)wrote on 14 Oct 2019, 12:39 last edited by asmant@J-Hilk I have set locale to English in the main.cpp. Do I have to do it somewhere else?
QLocale locale = QLocale(QLocale::English); QLocale::setDefault(locale);
-
@J-Hilk I have set locale to English in the main.cpp. Do I have to do it somewhere else?
QLocale locale = QLocale(QLocale::English); QLocale::setDefault(locale);
wrote on 14 Oct 2019, 13:22 last edited by Cobra91151Hello!
@J-Hilk meant to use the
dateTimeFormat
(https://doc.qt.io/qt-5/qlocale.html#dateTimeFormat) function, it will return the date format used for the current locale.Also, you can try out my solution:
QLocale testLocale = QLocale(QLocale::English, QLocale::UnitedStates); QString dateTimeText = testLocale.toString(QDateTime::currentDateTime(), "dddd / dd / MMMM / yyyy / hh:mm:ss AP"); qDebug() << dateTimeText;
It will display date time using
English
locale (United States). You can changeQLocale
and format it to your needs. Happy coding! -
Hello!
@J-Hilk meant to use the
dateTimeFormat
(https://doc.qt.io/qt-5/qlocale.html#dateTimeFormat) function, it will return the date format used for the current locale.Also, you can try out my solution:
QLocale testLocale = QLocale(QLocale::English, QLocale::UnitedStates); QString dateTimeText = testLocale.toString(QDateTime::currentDateTime(), "dddd / dd / MMMM / yyyy / hh:mm:ss AP"); qDebug() << dateTimeText;
It will display date time using
English
locale (United States). You can changeQLocale
and format it to your needs. Happy coding!wrote on 15 Oct 2019, 07:18 last edited by@Cobra91151 That's what I wanted to do. Thank you!