parse and fromat iso8601 datetime

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#!/usr/bin/env python
import datetime
## easy_install iso8601
from iso8601 import parse_date as from_iso8601
def to_iso8601(d):
if d.utcoffset() == None or d.utcoffset() == datetime.timedelta(0):
return d.replace(microsecond=0, tzinfo=None).isoformat() + 'Z'
return d.replace(microsecond=0).isoformat()