timefmt.py 文件源码

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

项目:PyMal 作者: cysinfo 项目源码 文件源码
def display_datetime(dt, custom_tz = None):
    """Returns a string from a datetime according to the display TZ (or a custom one"""
    timeformat = "%Y-%m-%d %H:%M:%S %Z%z"
    if dt.tzinfo is not None and dt.tzinfo.utcoffset(dt) is not None:
        if custom_tz is not None:
            dt = dt.astimezone(custom_tz)
        elif config.TZ is not None:
            if isinstance(config.TZ, str):
                secs = calendar.timegm(dt.timetuple())
                os.environ['TZ'] = config.TZ
                time.tzset()
                # Remove the %z which appears not to work
                timeformat = timeformat[:-2]
                return time.strftime(timeformat, time.localtime(secs))
            else:
                dt = dt.astimezone(config.tz)
    return ("{0:" + timeformat + "}").format(dt)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号