def date_as_iso8601(self):
from dateutil.tz import tzlocal
ts = self.meta.get("date", None)
if ts is None: return None
# TODO: Take timezone from config instead of tzlocal()
tz = tzlocal()
ts = ts.astimezone(tz)
offset = tz.utcoffset(ts)
offset_sec = (offset.days * 24 * 3600 + offset.seconds)
offset_hrs = offset_sec // 3600
offset_min = offset_sec % 3600
if offset:
tz_str = '{0:+03d}:{1:02d}'.format(offset_hrs, offset_min // 60)
else:
tz_str = 'Z'
return ts.strftime("%Y-%m-%d %H:%M:%S") + tz_str
评论列表
文章目录