utils.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:marvin 作者: BotDevGroup 项目源码 文件源码
def localized_date(date=None, timezone=None):
    """
    Returns the given date, localized to the default timezone.

    If no date is given, return the localized current date.

    timezone should be a valid timezone object obtained via pytz.
    """
    if not timezone:
        timezone = TZ

    if not date:
        date = pytz.utc.localize(datetime.utcnow())
    if not date.tzinfo:
        # Attempt to guezz current server timezone
        # Should be ok for any date coming fom a naive call to datetime.now()
        date = date.replace(tzinfo=tzlocal())

    return date.astimezone(timezone)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号