当前位置: 首页>>代码示例>>Python>>正文


Python TimePointParser.get_info方法代码示例

本文整理汇总了Python中isodatetime.parsers.TimePointParser.get_info方法的典型用法代码示例。如果您正苦于以下问题:Python TimePointParser.get_info方法的具体用法?Python TimePointParser.get_info怎么用?Python TimePointParser.get_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在isodatetime.parsers.TimePointParser的用法示例。


在下文中一共展示了TimePointParser.get_info方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_unix_time_from_time_string

# 需要导入模块: from isodatetime.parsers import TimePointParser [as 别名]
# 或者: from isodatetime.parsers.TimePointParser import get_info [as 别名]
def get_unix_time_from_time_string(datetime_string):
    """Convert a datetime string into a unix timestamp.

    The datetime_string must match DATE_TIME_FORMAT_EXTENDED above,
    which is the extended ISO 8601 year-month-dayThour:minute:second format,
    plus a valid ISO 8601 time zone. For example, 2016-09-07T11:21:00+01:00,
    2016-12-25T06:00:00Z, or 2016-12-25T06:00:00+13.

    isodatetime is not used to do the whole parsing, partly for performance,
    but mostly because the calendar may be in non-Gregorian mode.

    """
    try:
        date_time_utc = datetime.strptime(
            datetime_string, DATE_TIME_FORMAT_EXTENDED + "Z")
    except ValueError:
        global PARSER
        if PARSER is None:
            from isodatetime.parsers import TimePointParser
            PARSER = TimePointParser()
        time_zone_info = PARSER.get_info(datetime_string)[1]
        time_zone_hour = int(time_zone_info["time_zone_hour"])
        time_zone_minute = int(time_zone_info.get("time_zone_minute", 0))
        offset_seconds = 3600 * time_zone_hour + 60 * time_zone_minute
        if "+" in datetime_string:
            datetime_string, time_zone_string = datetime_string.split("+")
        else:
            datetime_string, time_zone_string = datetime_string.rsplit("-", 1)
        date_time = datetime.strptime(
            datetime_string, DATE_TIME_FORMAT_EXTENDED)
        date_time_utc = date_time - timedelta(seconds=offset_seconds)
    return timegm(date_time_utc.timetuple())
开发者ID:oliver-sanders,项目名称:cylc,代码行数:34,代码来源:wallclock.py


注:本文中的isodatetime.parsers.TimePointParser.get_info方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。