def local_datetime(utcdatetime, format=None, timezone=None):
"""
Return local datetime based on the timezone
It will automatically format the date.
To not format the date, set format=False
:param utcdatetime: Arrow or string
:param format: string of format or False
:param timezone: string, ie: US/Eastern
:return:
"""
if utcdatetime is None:
return None
timezone = timezone or config("DATETIME_TIMEZONE", "US/Eastern")
dt = utcdatetime.to(timezone) \
if isinstance(utcdatetime, arrow.Arrow) \
else arrow.get(utcdatetime, timezone)
if format is False:
return dt
_ = config("DATETIME_FORMAT")
format = _.get("default") or "MM/DD/YYYY" if not format else _.get(format)
return dt.format(format)
评论列表
文章目录