Skip to content

Instantly share code, notes, and snippets.

@spatialtime
Last active May 12, 2020 16:01
Show Gist options
  • Save spatialtime/0e1ec9c6df4fd752f8f5bfc05bb9b231 to your computer and use it in GitHub Desktop.
Save spatialtime/0e1ec9c6df4fd752f8f5bfc05bb9b231 to your computer and use it in GitHub Desktop.
Pythonic formatting and parsing of ISO 8601 weeks.
# This snippet demonstrates Pythonic formatting and parsing of
# ISO 8601 weeks.
# The first ISO week of the year is the first week containing
# a Thursday.
# ISO weeks begin on Monday, with Monday being day 1.
from datetime import datetime
d = datetime.strptime("2020-W17-7", "%G-W%V-%u")
print(format(d, "%G-W%V-%u"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment