bloglike:2021-10
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| bloglike:2021-10 [2021/10/17 05:48] – add signature stybla | bloglike:2021-10 [2021/10/17 06:41] (current) – PyQt5, QDateTime, UTC and localtime/timezone stybla | ||
|---|---|---|---|
| Line 10: | Line 10: | ||
| --- // | --- // | ||
| + | |||
| + | |||
| + | ===== 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.1634467697.txt.gz · Last modified: by stybla
