parse¶
-
rolex.parse.
datetime_template_and_example
= [('%Y-%m-%d %H:%M:%S', '2014-01-15 17:58:31'), ('%Y-%m-%d %H:%M:%S.%f', '2014-01-15 17:58:31.1234'), ('%Y-%m-%d %H:%M', '2014-01-15 17:58'), ('%Y-%m-%d %I:%M:%S %p', '2014-01-15 5:58:31 PM'), ('%Y-%m-%d %I:%M %p', '2014-01-15 05:58 PM'), ('%Y-%m-%d %I %p', '2014-01-15 05 PM'), ('%m-%d-%Y %H:%M:%S', '1-15-2014 17:58:31'), ('%m-%d-%Y %H:%M:%S.%f', '1-15-2014 17:58:31.1234'), ('%m-%d-%Y %H:%M', '1-15-2014 17:58'), ('%m-%d-%Y %I:%M:%S %p', '1-15-2014 5:58:31 PM'), ('%m-%d-%Y %I:%M %p', '1-15-2014 05:58 PM'), ('%m-%d-%Y %I %p', '1-15-2014 05 PM'), ('%Y/%m/%d %H:%M:%S', '2014/01/15 17:58:31'), ('%Y/%m/%d %H:%M:%S.%f', '2014/01/15 17:58:31.1234'), ('%Y/%m/%d %H:%M', '2014/01/15 17:58'), ('%Y/%m/%d %I:%M:%S %p', '2014/01/15 5:58:31 PM'), ('%Y/%m/%d %I:%M %p', '2014/01/15 05:58 PM'), ('%Y/%m/%d %I %p', '2014/01/15 05 PM'), ('%m/%d/%Y %H:%M:%S', '1/15/2014 17:58:31'), ('%m/%d/%Y %H:%M:%S.%f', '1/15/2014 17:58:31.1234'), ('%m/%d/%Y %H:%M', '1/15/2014 17:58'), ('%m/%d/%Y %I:%M:%S %p', '1/15/2014 5:58:31 PM'), ('%m/%d/%Y %I:%M %p', '1/15/2014 05:58 PM'), ('%m/%d/%Y %I %p', '1/15/2014 05 PM'), ('%H:%M:%S %m/%d/%Y', '17:58:31 1/15/2014'), ('%H:%M:%S.%f %m/%d/%Y', '17:58:31.1234 1/15/2014'), ('%H:%M %m/%d/%Y', '17:58 1/15/2014'), ('%I:%M:%S %p %m/%d/%Y', '5:58:31 PM 1/15/2014'), ('%I:%M %p %m/%d/%Y', '05:58 PM 1/15/2014'), ('%I %p %m/%d/%Y', '05 PM 1/15/2014'), ('%Y%m%d%H', '2014011506'), ('%Y%m%d%H%M', '201401150630'), ('%Y%m%d%H%M%S', '20140115063015'), ('%Y%m%d%H%M%S.%f', '20140115063015.123'), ('%y%m%d%H', '14011506'), ('%y%m%d%H%M', '1401150630'), ('%y%m%d%H%M%S', '140115063015'), ('%y%m%d%H%M%S.%f', '140115063015.123'), ('%Y-%m-%dT%H:%M:%S', '2014-01-15T17:58:31'), ('%Y-%m-%dT%H:%M:%S.%f', '2014-01-15T17:58:31.1234'), ('%Y-%m-%dT%H:%M:%SZ%Z', '2014-01-15T17:58:31ZUTC'), ('%Y-%m-%dT%H:%M:%S.%fZ%Z', '2014-01-15T17:58:31.1234ZUTC'), ('%a, %d %b %Y %H:%M:%S GMT', 'Wed, 15 Jan 2014 17:58:31 GMT'), ('%Y-%m-%d', '2014-09-20'), ('%m-%d-%Y', '09-20-2014'), ('%Y/%m/%d', '2014/09/20'), ('%m/%d/%Y', '09/20/2014'), ('%Y.%m.%d', '2014.09.20'), ('%m.%d.%Y', '9.20.2014'), ('%B %d, %Y', 'September 20, 2014'), ('%A, %B %d, %Y', 'Saturday, September 20, 2014'), ('%b %d, %Y', 'Sep 20, 2014'), ('%a, %b %d, %Y', 'Sat, Sep 20, 2014'), ('%Y%m%d', '20140920'), ('%y%m%d', '140920'), ('%m%d%Y', '09202014'), ('%m%d%y', '092014')]¶ Date, DateTime string template.
Reference: https://msdn.microsoft.com/en-us/library/hc4ky857.aspx
-
class
rolex.parse.
Parser
[source]¶ datetime string parser.
-
str2date
(date_str)[source]¶ Parse date from string.
If there’s no template matches your string, Please go https://github.com/MacHu-GWU/rolex-project/issues submit your datetime string. I ‘ll update templates ASAP.
This method is faster than
dateutil.parser.parse()
.Parameters: date_str (str) – a string represent a date Returns: a date object 中文文档
从string解析date。首先尝试默认模板, 如果失败了, 则尝试所有的模板。 一旦尝试成功, 就将当前成功的模板保存为默认模板。这样做在当你待解析的 字符串非常多, 且模式单一时, 只有第一次尝试耗时较多, 之后就非常快了。 该方法要快过
dateutil.parser.parse()
方法。
-
str2datetime
(datetime_str)¶ Parse datetime from string.
If there’s no template matches your string, Please go https://github.com/MacHu-GWU/rolex-project/issues submit your datetime string. I ‘ll update templates ASAP.
This method is faster than
dateutil.parser.parse()
.Parameters: datetime_str (str) – a string represent a datetime Returns: a datetime object 中文文档
从string解析datetime。首先尝试默认模板, 如果失败了, 则尝试所有的模板。 一旦尝试成功, 就将当前成功的模板保存为默认模板。这样做在当你待解析的 字符串非常多, 且模式单一时, 只有第一次尝试耗时较多, 之后就非常快了。 该方法要快过
dateutil.parser.parse()
方法。为了防止模板库失败的情况, 程序设定在失败后自动一直启用
dateutil.parser.parse()
进行解析。你可以调用Parser.reset()
方法恢复默认设定。
-