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


Python Utils.parsedate_tz方法代码示例

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


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

示例1: parse_date

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import parsedate_tz [as 别名]
def parse_date(value):
    """Parse one of the following date formats into a datetime object:

    .. sourcecode:: text

        Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
        Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
        Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() format

    If parsing fails the return value is `None`.

    :param value: a string with a supported date format.
    :return: a :class:`datetime.datetime` object.
    """
    if value:
        t = parsedate_tz(value.strip())
        if t is not None:
            try:
                year = t[0]
                # unfortunately that function does not tell us if two digit
                # years were part of the string, or if they were prefixed
                # with two zeroes.  So what we do is to assume that 69-99
                # refer to 1900, and everything below to 2000
                if year >= 0 and year <= 68:
                    year += 2000
                elif year >= 69 and year <= 99:
                    year += 1900
                return datetime(*((year,) + t[1:7])) - timedelta(seconds=t[-1] or 0)
            except (ValueError, OverflowError):
                return None 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:32,代码来源:http.py

示例2: parse_date

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import parsedate_tz [as 别名]
def parse_date(value):
    """Parse one of the following date formats into a datetime object:

    .. sourcecode:: text

        Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
        Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
        Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() format

    If parsing fails the return value is `None`.

    :param value: a string with a supported date format.
    :return: a :class:`datetime.datetime` object.
    """
    if value:
        t = parsedate_tz(value.strip())
        if t is not None:
            try:
                year = t[0]
                # unfortunately that function does not tell us if two digit
                # years were part of the string, or if they were prefixed
                # with two zeroes.  So what we do is to assume that 69-99
                # refer to 1900, and everything below to 2000
                if year >= 0 and year <= 68:
                    year += 2000
                elif year >= 69 and year <= 99:
                    year += 1900
                return datetime(*((year,) + t[1:7])) - \
                    timedelta(seconds=t[-1] or 0)
            except (ValueError, OverflowError):
                return None 
开发者ID:jpush,项目名称:jbox,代码行数:33,代码来源:http.py

示例3: test_parsedate_no_dayofweek

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import parsedate_tz [as 别名]
def test_parsedate_no_dayofweek(self):
        eq = self.assertEqual
        eq(Utils.parsedate_tz('25 Feb 2003 13:47:26 -0800'),
           (2003, 2, 25, 13, 47, 26, 0, 1, -1, -28800)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_email.py

示例4: test_parsedate_compact_no_dayofweek

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import parsedate_tz [as 别名]
def test_parsedate_compact_no_dayofweek(self):
        eq = self.assertEqual
        eq(Utils.parsedate_tz('5 Feb 2003 13:47:26 -0800'),
           (2003, 2, 5, 13, 47, 26, 0, 1, -1, -28800)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_email.py

示例5: test_parsedate_acceptable_to_time_functions

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import parsedate_tz [as 别名]
def test_parsedate_acceptable_to_time_functions(self):
        eq = self.assertEqual
        timetup = Utils.parsedate('5 Feb 2003 13:47:26 -0800')
        t = int(time.mktime(timetup))
        eq(time.localtime(t)[:6], timetup[:6])
        eq(int(time.strftime('%Y', timetup)), 2003)
        timetup = Utils.parsedate_tz('5 Feb 2003 13:47:26 -0800')
        t = int(time.mktime(timetup[:9]))
        eq(time.localtime(t)[:6], timetup[:6])
        eq(int(time.strftime('%Y', timetup[:9])), 2003) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_email.py

示例6: test_parsedate_y2k

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import parsedate_tz [as 别名]
def test_parsedate_y2k(self):
        """Test for parsing a date with a two-digit year.

        Parsing a date with a two-digit year should return the correct
        four-digit year. RFC822 allows two-digit years, but RFC2822 (which
        obsoletes RFC822) requires four-digit years.

        """
        self.assertEqual(Utils.parsedate_tz('25 Feb 03 13:47:26 -0800'),
                         Utils.parsedate_tz('25 Feb 2003 13:47:26 -0800'))
        self.assertEqual(Utils.parsedate_tz('25 Feb 71 13:47:26 -0800'),
                         Utils.parsedate_tz('25 Feb 1971 13:47:26 -0800')) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_email.py

示例7: parse_date

# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import parsedate_tz [as 别名]
def parse_date(value):
    """Parse one of the following date formats into a datetime object:

    .. sourcecode:: text

        Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
        Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
        Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() format

    If parsing fails the return value is `None`.

    :param value: a string with a supported date format.
    :return: a :class:`datetime.datetime` object.
    """
    if value:
        t = parsedate_tz(value.strip())
        if t is not None:
            try:
                year = t[0]
                # unfortunately that function does not tell us if two digit
                # years were part of the string, or if they were prefixed
                # with two zeroes.  So what we do is to assume that 69-99
                # refer to 1900, and everything below to 2000
                if year >= 0 and year <= 68:
                    year += 2000
                elif year >= 69 and year <= 99:
                    year += 1900
                return datetime(*((year,) + t[1:7])) - \
                       timedelta(seconds=t[-1] or 0)
            except (ValueError, OverflowError):
                return None 
开发者ID:chalasr,项目名称:Flask-P2P,代码行数:33,代码来源:http.py


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