Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
date time question
#2
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 Doh
>>> 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
Reply


Messages In This Thread
date time question - by pythonlearner1 - Jan-31-2020, 06:11 PM
RE: date time question - by snippsat - Jan-31-2020, 06:58 PM
RE: date time question - by pythonlearner1 - Jan-31-2020, 08:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare current date on calendar with date format file name Fioravanti 1 311 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Date Time Series Help...Please spra8560 2 431 Feb-01-2024, 01:38 PM
Last Post: spra8560
  Python date format changes to date & time 1418 4 715 Jan-20-2024, 04:45 AM
Last Post: 1418
  Downloading time zone aware files, getting wrong files(by date))s tester_V 9 1,144 Jul-23-2023, 08:32 AM
Last Post: deanhystad
  Formatting a date time string read from a csv file DosAtPython 5 1,434 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  Wait til a date and time KatManDEW 2 1,470 Mar-11-2022, 08:05 PM
Last Post: KatManDEW
  Date format and past date check function Turtle 5 4,398 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  How to add previous date infront of every unique customer id's invoice date ur_enegmatic 1 2,282 Feb-06-2021, 10:48 PM
Last Post: eddywinch82
  Naming the file as time and date. BettyTurnips 3 3,069 Jan-15-2021, 07:52 AM
Last Post: BettyTurnips
  Update Date based on Time/String stevezemlicka 1 2,055 Jan-08-2021, 06:54 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020