In this quick tip, we will see how to format a python date to the ISO 8601 standard.
If you are using Python 3+, the iso formatting option is built in. Just call the
isoformat method on a datetime object.
from datetime import datetime now = datetime.now() print(now.isoformat())
If you are using Python 2, you will need to pass in the standard format using the
strftime method and the iso format string.
from datetime import datetime now = datetime.now() print(now.strftime('%Y-%m-%dT%H:%M:%S.%f%z'))