time.strptime的格式化【time.strptime格式化实例】

358次阅读
没有评论

time.strptime的格式化【time.strptime格式化实例】

在python的时间使用时,我们无非就是输出字符串的形式,又或者是其他的形式跟字符串之间的来回转换。时间数组对于我们获取具体的年或是天数,都是常用的首段。本篇需要讲到的time.strptime函数,就是把字符串转换成时间元组的方法。在接下来的内容中就其函数的概念、语法、参数、返回值和实例分别介绍。

time.strptime概念

能够根据指定的格式把一个时间字符串解析为时间元组。

time.strptime语法

time.strptime(string[, format])

time.strptime参数

string — 时间字符串。

format — 格式化字符串。

time.strptime返回值

返回struct_time对象。

time.strptime实例

print(time.strptime("2020-12-15","%Y-%m-%d"))

输出

time.struct_time(tm_year=2020, tm_mon=12, tm_mday=15, tm_hour=10, tm_min=04)

以上就是python中time.strptime的格式化,运行上方代码结果后,我们可以清晰的得知对应的年、月、日等信息。大家都这类使用需要的,不妨试试time.strptime函数吧。

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2021-05-08发表,共计542字。
新手QQ群:570568346,欢迎进群讨论 Python51学习