bloglike:2021-10
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
bloglike:2021-10 [2021/10/16 13:37] – created + buying from China stybla | bloglike:2021-10 [2021/10/17 06:41] (current) – PyQt5, QDateTime, UTC and localtime/timezone stybla | ||
---|---|---|---|
Line 8: | Line 8: | ||
I'm not complaining, | I'm not complaining, | ||
+ | |||
+ | --- // | ||
+ | |||
+ | |||
+ | ===== PyQt5, QDateTime, UTC and localtime/ | ||
+ | |||
+ | I cannot believe it took me hour or longer to figure this one out: | ||
+ | |||
+ | <code python> | ||
+ | from PyQt5.QtCore import QDateTime | ||
+ | from PyQt5.QtCore import QTimeZone | ||
+ | |||
+ | utc_datetime = QDateTime.fromString(' | ||
+ | utc_datetime.setTimeZone(QTimeZone.utc()) | ||
+ | local_datetime = utc_datetime.toLocalTime() | ||
+ | print(local_datetime.toString(' | ||
+ | # ' | ||
+ | </ | ||
+ | |||
+ | Actually, I needed something like this: | ||
+ | |||
+ | <code python> | ||
+ | from PyQt5.QtCore import QDateTime | ||
+ | from PyQt5.QtCore import QTimeZone | ||
+ | |||
+ | local_datetime = QDateTime.currentDateTime() | ||
+ | print(' | ||
+ | utc_datetime = local_datetime.toUTC() | ||
+ | stored_dt = utc_datetime.toString(" | ||
+ | print(' | ||
+ | utc_datetime = QDateTime.fromString(stored_dt, | ||
+ | utc_datetime.setTimeZone(QTimeZone.utc()) | ||
+ | print(' | ||
+ | local_datetime = utc_datetime.toLocalTime() | ||
+ | print(' | ||
+ | </ | ||
+ | |||
+ | In other words convert local date and time into UTC, store it as a a string and then restore it. Whether it makes sense or not, that's another question. Now, the problem was to figure out how to set that timezone or something. No, '' | ||
+ | |||
+ | --- // |
bloglike/2021-10.txt · Last modified: 2021/10/17 06:41 by stybla