datetime - python
ISO 8601 / RFC 3339
# This function returns both ISO 8601 compatible and RFC 3339 unlike the isoformat() function
def convert_to_iso_8601(datetime_obj):
# returns iso8601 string
return datetime_obj.strftime('%Y-%m-%dT%H:%M:%SZ')
def convert_from_iso_8601(iso8601_string):
# returns datetime obj
return datetime.datetime.strptime(iso8601_string, '%Y-%m-%dT%H:%M:%SZ')
Operations
import datetime
# return is a datetime object
dt = datetime.datetime.now() - datetime.timedelta(days=1, hours=2, minutes=30)
# or subtract datetimes directly
datetime.datetime.now() - dt