在Python中操作时间之strptime()方法的使用
发布时间:2020-12-17 08:34:33 所属栏目:Python 来源:网络整理
导读:strptime()方法分析表示根据格式的时间字符串。返回值是一个struct_time所返回gmtime()或localtime()。 格式参数使用相同的指令使用strftime();它默认为“%a %b %d %H:%M:%S %Y”相匹配的ctime()所返回的格式。 如果字符串不能按格式进行解析,或者如果它具
strptime()方法分析表示根据格式的时间字符串。返回值是一个struct_time所返回gmtime()或localtime()。 格式参数使用相同的指令使用strftime();它默认为“%a %b %d %H:%M:%S %Y”相匹配的ctime()所返回的格式。 如果字符串不能按格式进行解析,或者如果它具有解析后多余的数据,ValueError被挂起。 以下是strptime()方法的语法: time.strptime(string[,format]) 参数
下面的指令可以嵌入格式字符串:
返回值 这个返回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,3,335,-1) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |