def load(self, raw_value):
"""Converts an input raw value into a timestamp.
Returns: Datetime object, if the conversion succeeds;
None, if the conversion fails.
raw_value -- The raw value, in string format (eg. '2014-12-20 15:01:02'),
or in milliseconds since Epoch (eg. 1293581619000)
"""
if isinstance(raw_value, str):
try:
timestamp = datetime.strptime(raw_value, "%Y-%m-%d %H:%M:%S")
except:
timestamp = None
else:
try:
timestamp = datetime.utcfromtimestamp(float(raw_value)/1000)
except:
timestamp = None
return timestamp
评论列表
文章目录