util.py 文件源码

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

项目:blobxfer 作者: Azure 项目源码 文件源码
def datetime_from_timestamp(ts, tz=None, as_utc=False):
    # type: (float, dateutil.tz, bool) -> datetime.datetime
    """Convert a timestamp into datetime with offset
    :param float ts: timestamp
    :param dateutil.tz tz: time zone or local tz if not specified
    :param bool as_utc: convert datetime to UTC
    :rtype: datetime.datetime
    :return: converted timestamp to datetime
    """
    if tz is None:
        tz = dateutil.tz.tzlocal()
    dt = datetime.datetime.fromtimestamp(ts, tz=tz)
    if as_utc:
        return dt.astimezone(tz=dateutil.tz.tzutc())
    else:
        return dt
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号