Solved time zone other than UTC and local in QDateTimeEdit
-
I have a
QDateTimeEdit
in a form that I need to show times from time zones other than UTC and local. It's showing the time from an embedded device that might not be in the same time zone as the running form. Is there a way to do this? -
You can basically set any date and time you want with setDateTime
or with the constructor -
@koahnig I know that, but I can only seem to get it to display in UTC or machine's local time zone. I need a way to have the functionality of
QDateTimeEdit
plus have it display the time in a specified time zone. -
You need to show code snippet.
QDateTime allows you to retrieve through its static members currentDateTime the current local date and time and there is also the UTC variant. When you are using those static members for initialization of QDateTimeEdit you are certainly getting local respectively UTC.
However, you would need to initialize an instance of QDateTime with the value you like to use (e.g. using setDate or setTime.
-
@koahnig What I need is the editability of
QDateTimeEdit
, but have control over the time zone the widget displays in. -
What I discovered is that I needed to use
QDateTime::toTimeZone(const QTineZone&)
to convert the time and useQDateTimeEdit::setTimeSpec(Qt::TimeZone)
on the widget.