strptime()方法分析表示根据格式的时间字符串。返回值是一个struct_time所返回gmtime()或localtime()。
格式参数使用相同的指令使用strftime();它默认为“%a %b %d %H:%M:%S %Y”相匹配的ctime()所返回的格式。
如果字符串不能按格式进行解析,或者如果它具有解析后多余的数据,ValueError被挂起。
语法
以下是strptime()方法的语法:
time.strptime(string[, format])
参数
下面的指令可以嵌入格式字符串:
指令
返回值
立即学习“Python免费学习笔记(深入)”;
这个返回struct_time所返回gmtime()或localtime()的值。
例子
下面的例子显示 strptime()方法的使用。
#!/usr/bin/python
import time
struct_time = time.strptime("30 Nov 00", "%d %b %y")
print "returned tuple: %s " % struct_time
When we run above program, it produces following result:
returned tuple: (2000, 11, 30, 0, 0, 0, 3, 335, -1)
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号