• 技术文章 >Python技术 >Python基础教程

    python time.strptime的格式化

    小妮浅浅小妮浅浅2021-04-28 11:08:24原创2776

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

    1.概念

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

    2.语法

    time.strptime(string[, format])

    3.参数

    string -- 时间字符串。

    format -- 格式化字符串。

    4.返回值

    返回struct_time对象。

    5.实例

    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函数吧。

    (推荐操作系统:windows7系统、Python 3.9.1,DELL G3电脑。)

    专题推荐:python timestrptime
    品易云
    上一篇:python中Array和DataFrame如何相互转换 下一篇:python strftime和strptime的不同分析

    相关文章推荐

    • python time.clock()的出错解决• time.localtime在python中的使用• python字典获取对应键的方法• python sleep和wait对比分析• python中如何按行遍历Dataframe• python中获取如何Series值• time.ctime()在python中的使用• python中time.mktime()的转换

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网