Jan-31-2020, 06:58 PM
Use code tags.
(Jan-31-2020, 06:11 PM)pythonlearner1 Wrote: I also want to add timezone "Etc/UTC" to it.If timezone is involved i now use only Pendulum,before it often was a combination of datetime, dateutil, pytz ..ect
>>> import pendulum >>> >>> d = doc.get('submitted') >>> d '2020-01-25 20:10:10' >>> pendulum.parse(d) DateTime(2020, 1, 25, 20, 10, 10, tzinfo=Timezone('UTC')) >>> print(pendulum.parse(d)) 2020-01-25T20:10:10+00:00 >>> >>> ts = doc.get('timestamp') >>> ts 1579624522874 >>> ts = ts / 1000 >>> pendulum.from_timestamp(ts) DateTime(2020, 1, 21, 16, 35, 22, 874000, tzinfo=Timezone('UTC')) >>> print(pendulum.from_timestamp(ts)) 2020-01-21T16:35:22.874000+00:00