Python Forum

Full Version: Converting timestamp like 2023-04-18T20:00:10.000Z to 20230418200010
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

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

Thanks in advance,
Regards,
Den.
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"))
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")