當前位置: 首頁>>代碼示例>>Python>>正文


Python _strptime._strptime_datetime方法代碼示例

本文整理匯總了Python中_strptime._strptime_datetime方法的典型用法代碼示例。如果您正苦於以下問題:Python _strptime._strptime_datetime方法的具體用法?Python _strptime._strptime_datetime怎麽用?Python _strptime._strptime_datetime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在_strptime的用法示例。


在下文中一共展示了_strptime._strptime_datetime方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: strptime

# 需要導入模塊: import _strptime [as 別名]
# 或者: from _strptime import _strptime_datetime [as 別名]
def strptime(string, _format):
    import _strptime
    return _strptime._strptime_datetime(to_struct_time, string, _format)

# All the clock_xx machinery shouldn't work in the browser so some
# NotImplementedErrors or messages are shown 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:8,代碼來源:time.py

示例2: strptime

# 需要導入模塊: import _strptime [as 別名]
# 或者: from _strptime import _strptime_datetime [as 別名]
def strptime(cls, date_string, format):
        'string, format -> new datetime parsed from a string (like time.strptime()).'
        import _strptime
        return _strptime._strptime_datetime(cls, date_string, format) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:6,代碼來源:datetime.py

示例3: test_strptime

# 需要導入模塊: import _strptime [as 別名]
# 或者: from _strptime import _strptime_datetime [as 別名]
def test_strptime(self):
        string = '2004-12-01 13:02:47.197'
        format = '%Y-%m-%d %H:%M:%S.%f'
        expected = _strptime._strptime_datetime(self.theclass, string, format)
        got = self.theclass.strptime(string, format)
        self.assertEqual(expected, got)
        self.assertIs(type(expected), self.theclass)
        self.assertIs(type(got), self.theclass)

        strptime = self.theclass.strptime
        self.assertEqual(strptime("+0002", "%z").utcoffset(), 2 * MINUTE)
        self.assertEqual(strptime("-0002", "%z").utcoffset(), -2 * MINUTE)
        # Only local timezone and UTC are supported
        for tzseconds, tzname in ((0, 'UTC'), (0, 'GMT'),
                                 (-_time.timezone, _time.tzname[0])):
            if tzseconds < 0:
                sign = '-'
                seconds = -tzseconds
            else:
                sign ='+'
                seconds = tzseconds
            hours, minutes = divmod(seconds//60, 60)
            dtstr = "{}{:02d}{:02d} {}".format(sign, hours, minutes, tzname)
            dt = strptime(dtstr, "%z %Z")
            self.assertEqual(dt.utcoffset(), timedelta(seconds=tzseconds))
            self.assertEqual(dt.tzname(), tzname)
        # Can produce inconsistent datetime
        dtstr, fmt = "+1234 UTC", "%z %Z"
        dt = strptime(dtstr, fmt)
        self.assertEqual(dt.utcoffset(), 12 * HOUR + 34 * MINUTE)
        self.assertEqual(dt.tzname(), 'UTC')
        # yet will roundtrip
        self.assertEqual(dt.strftime(fmt), dtstr)

        # Produce naive datetime if no %z is provided
        self.assertEqual(strptime("UTC", "%Z").tzinfo, None)

        with self.assertRaises(ValueError): strptime("-2400", "%z")
        with self.assertRaises(ValueError): strptime("-000", "%z") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:41,代碼來源:datetimetester.py


注:本文中的_strptime._strptime_datetime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。