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


Forum Jump:

User Panel Messages

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