def timestamp_for_metadata(dt=None):
"""
Return a timestamp with a timezone for the configured locale. If all else
fails, consider localtime to be UTC.
Originally written by Marco Bonetti.
"""
dt = dt or datetime.datetime.now()
if timezone is None:
return dt.strftime('%Y-%m-%d %H:%M%z')
if not dt.tzinfo:
tz = timezone.get_current_timezone()
if not tz:
tz = timezone.utc
dt = dt.replace(tzinfo=timezone.get_current_timezone())
return dt.strftime("%Y-%m-%d %H:%M%z")
评论列表
文章目录