You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
471 B
Python
17 lines
471 B
Python
|
|
import pytz
|
|
import datetime
|
|
|
|
def string_to_datetime( s ):
|
|
if s is None:
|
|
return None
|
|
try:
|
|
return datetime.datetime.strptime( s, "%Y-%m-%dT%H:%M:%S.%fZ" ).replace( tzinfo = pytc.utc )
|
|
except ValueError:
|
|
return datetime.datetime.strptime( s, "%Y-%m-%dT%H:%M:%SZ" ).replace( tzinfo = pytc.utc )
|
|
|
|
def datetime_to_string( dt ):
|
|
if dt is None:
|
|
return None
|
|
return dt.astimezone( pytz.utc ).strftime( "%Y-%m-%dT%H:%M:%S.%fZ" )
|