Solved How get list all time zone?
-
Hi.
How get list all time zone with name and time?
It is:QTimeZone::availableTimeZoneIds();
return name time zone without time.
-
So hard to read the documentation?
-
hi @Mikeeeeee
you can use this method https://doc.qt.io/qt-5/qdatetime.html#QDateTime-4 -
@Christian-Ehrlicher said in How get list all time zone?:
read the documentation?
Very funny. In the documentation, I found only one suitable method and that one works poorly.
-
@LeLev said in How get list all time zone?:
this method will not help to get a list of all time zones.
-
@Mikeeeeee said in How get list all time zone?:
Very funny. In the documentation, I found only one suitable method and that one works poorly.
What "works poorly"? I see https://doc.qt.io/qt-5/qtimezone.html#availableTimeZoneIds to get a list of the ids, https://doc.qt.io/qt-5/qtimezone.html#QTimeZone-1 to create a
QTimeZone
off each of the available ids, and from the instance there is https://doc.qt.io/qt-5/qtimezone.html#displayName for the name and some other method for whatever you mean by "time", e,.g, https://doc.qt.io/qt-5/qtimezone.html#offsetFromUtc. So what does not work or is not in the documentation? -
@Mikeeeeee said in How get list all time zone?:
this method will not help
QList<QByteArray> timeZoneIds = QTimeZone::availableTimeZoneIds(); QDateTime localDateTime (QDate::currentDate(), QTime::currentTime()); for (int i = 0; i<timeZoneIds.length(); i++){ QDateTime dt = localDateTime.toTimeZone(QTimeZone(timeZoneIds.at(i))); qDebug()<<dt; }
-
@JonB thank!
The language for the output of time zone names depends on the language of the operating system?it is code works:
listTimeZome = QTimeZone::availableTimeZoneIds(); for(int i = 0; i < listTimeZome.size(); i++) { QTimeZone timeZone(listTimeZome[i]); QString displayNameTimeZone = timeZone.displayName(QTimeZone::StandardTime); int utc = timeZone.offsetFromUtc(QDateTime::currentDateTime()); qDebug()<< "name" << displayNameTimeZone; qDebug()<< "utc" << utc; }
-
@Mikeeeeee said in How get list all time zone?:
The language for the output of time zone names depends on the language of the operating system?
That I do not know. I do not see a method offering to translate these names into locale/language.