The sqlite3 timestamp conversion between unixepoch and localtime can't be done according to the timezone setting on the machine automatically.

hongy...@gmail.com hongyi.zhao at gmail.com
Sun Aug 29 22:49:19 EDT 2021


On Ubuntu 20.04.2 LTS, I use the [recent2](https://github.com/dotslash/recent2/blob/master/recent2.py) to log and query my bash history, which uses a sqlite3 database to store the history information. The `datetime` of running a command is inserted in the sqlite3 database with [a `unixepoch` format](https://github.com/dotslash/recent2/blob/f1018aee228c710cc7d1b8b93bc0228791a54563/recent2.py#L45), and it will be converted into `localtime` accordingly when retrieved and displayed later.

But I found that it did not perform the correct conversion according to the time zone setting on the machine, as shown below:
```shell
werner at X10DAi-00:~$ rm 222222222222222222
rm: cannot remove '222222222222222222': No such file or directory
werner at X10DAi-00:~$ recent -fo -w . 2222222222222
rm 222222222222222222                              # rtime@ 2021-08-29 10:57:13
werner at X10DAi-00:~$ date 
Sun 29 Aug 2021 06:57:22 PM CST
```
I also filed an issue [here](https://discuss.python.org/t/python-sqlite3-datetime-verconsion-between-unixepoch-and-localtime/10382). Any hints for this problem?

Regards,
HY


More information about the Python-list mailing list