用法:
time.strptime(string[, format])
根据格式解析表示时间的字符串。返回值是由
gmtime()
或localtime()
返回的struct_time
。format
参数使用的指令与strftime()
使用的指令相同;它默认为"%a %b %d %H:%M:%S %Y"
,它与ctime()
返回的格式匹配。如果string
无法根据format
解析,或者解析后有多余的数据,则会引发ValueError
。当无法推断出更准确的值时,用于填充任何缺失数据的默认值是(1900, 1, 1, 0, 0, 0, 0, 1, -1)
。string
和format
都必须是字符串。例如:
>>> import time >>> time.strptime("30 Nov 00", "%d %b %y") time.struct_time(tm_year=2000, tm_mon=11, tm_mday=30, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=335, tm_isdst=-1)
对
%Z
指令的支持基于tzname
中包含的值以及daylight
是否为真。因此,它是特定于平台的,除了识别始终已知的 UTC 和 GMT(并且被认为是非夏令时时区)。仅支持文档中指定的指令。因为
strftime()
是按平台实现的,它有时可以提供比所列指令更多的指令。但是strptime()
独立于任何平台,因此不一定支持所有未记录为支持的可用指令。
相关用法
- Python time.strftime用法及代码示例
- Python time.strftime()用法及代码示例
- Python time.sleep()用法及代码示例
- Python time.tzname()用法及代码示例
- Python time.monotonic()用法及代码示例
- Python time.tzset()用法及代码示例
- Python time.asctime()用法及代码示例
- Python time.clock()用法及代码示例
- Python time.daylight()用法及代码示例
- Python time.perf_counter()用法及代码示例
- Python time.get_clock_info()用法及代码示例
- Python time.gmtime()用法及代码示例
- Python time.time()用法及代码示例
- Python time.mktime()用法及代码示例
- Python time.thread_time()用法及代码示例
- Python time.clock_gettime_ns()用法及代码示例
- Python time.tzset用法及代码示例
- Python time.process_time_ns()用法及代码示例
- Python time.monotonic_ns()用法及代码示例
- Python time.perf_counter_ns()用法及代码示例
注:本文由纯净天空筛选整理自python.org大神的英文原创作品 time.strptime。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。