Skip to content

Instantly share code, notes, and snippets.

@spatialtime
Last active May 12, 2020 15:57
Show Gist options
  • Save spatialtime/7cd5c9ea974617369a96325d951ef755 to your computer and use it in GitHub Desktop.
Save spatialtime/7cd5c9ea974617369a96325d951ef755 to your computer and use it in GitHub Desktop.
Pythonic formatting and parsing of ISO 8601 ordinal dates.
# This snippet demonstrates Pythonic formatting and parsing of
# ISO 8601 ordinal dates (4-digit year + "-" + ordinal day).
# Note: an ordinal day in this context is the nth day of
# the year, with Jan 1 being ordinal day 1 and Dec 31
# of non-leap year (a "common year") being day 365.
from datetime import datetime
d = datetime.strptime("2020-355", "%Y-%j")
print(format(d, "%Y-%j"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment