Hello. What is the explanation for the following:
I query a record from the database with the time displayed in RFC3339 format. I get the UTC time, which was used to add the record (obviously).
> select “100-00817” from length where time = ‘2020-03-26T04:24:33.368129024Z’
> name: length
> time 100-00817
> ---- ---------
> 2020-03-26T04:24:33.368129024Z 77
Now I change the precision to ms and retrieve the same record again. The returned timestamp, however, is the local time (not so obvious).
> precision ms
> select “100-00817” from length where time = ‘2020-03-26T04:24:33.368129024Z’
name: length
time 100-00817
---- ---------
1585196673368 77
>>> datetime.fromtimestamp(1585196673.368)
datetime.datetime(2020, 3, 26, 17, 24, 33, 368000)
Thanks. You’re right. I got confused by the timestamp obtained from python’s datetime.datetime.utcnow().timestamp(), which returns a naive datetime of utc and timestamp() interprets it as local. Better to use datetime.datetime.now(timezone.utc).timestamp() or just datetime.datetime.now().timestamp(). >>> datetime.now(timezone.utc).timestamp() - datetime.utcnow().timestamp() 46800 >>> datetime.now(timezone.utc).timestamp() - datetime.now().timestamp() 0