Created
August 17, 2019 16:00
-
-
Save mattstibbs/a283f55a124d2de1b1d732daaac1f7f8 to your computer and use it in GitHub Desktop.
Add a colon to timezone offset when using datetime.strftime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
original_timestamp = datetime.datetime.now() | |
# Convert datetime object to a string representation | |
timestamp_string = original_timestamp.strftime("%Y-%m-%dT%H:%M:%S%z") | |
print(timestamp_string) | |
# OUTPUT: 2019-08-17T00:00:00+0000 | |
# Add a colon separator to the offset segment | |
timestamp_string = "{0}:{1}".format( | |
timestamp_string[:-2], | |
timestamp_string[-2:] | |
) | |
print(timestamp_string) | |
# OUTPUT: 2019-08-17T00:00:00+00:00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment