Python Forum
Converting timestamp like 2023-04-18T20:00:10.000Z to 20230418200010
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting timestamp like 2023-04-18T20:00:10.000Z to 20230418200010
#1
Hi,

how to convert a timestamp like 2023-04-18T20:00:10.000Z to 20230418200010 ?

Thanks in advance,
Regards,
Den.
Reply
#2
Solved.

			from datetime import datetime

			date = datetime.strptime("$1", "%Y-%m-%dT%H:%M:%S.%f%z")
			print (date.strftime("%Y%m%d%H%M%S"))
buran write Apr-19-2023, 10:39 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#3
It's ISO8601 and the method datetime.fromiso interprets this standard.
Docs: https://docs.python.org/3/library/dateti...misoformat

timestamp = datetime.datetime.fromisoformat("2023-04-18T20:00:10.000Z")
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  error in timestamp Led_Zeppelin 3 3,241 Jun-15-2022, 08:28 PM
Last Post: deanhystad
  error in timestamp Led_Zeppelin 0 1,014 Jun-10-2022, 07:59 PM
Last Post: Led_Zeppelin
  Timestamp is undefined ErnestTBass 7 7,970 Feb-16-2019, 08:27 PM
Last Post: snippsat
  timestamp not updating bowen73 3 7,205 Aug-20-2017, 11:13 PM
Last Post: bowen73
  matplotlib timestamp zero_shubh0 2 6,830 Dec-02-2016, 02:12 PM
Last Post: zero_shubh0

Forum Jump:

User Panel Messages

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