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

    python中time.mktime()的转换

    小妮浅浅小妮浅浅2021-04-28 11:16:07原创4983

    对于当前时间的转换上,如果有人接触过localtime函数,就会发现mktime()的作用跟它相反,是专门用于对本地时间进行转换的。其最后的结果以秒来展示,方便了很多人对时间的直观理解。接下来我们对time.mktime()的概念、语法、参数、返回值进行学习,然后带来转换的实例用法。

    1.概念

    将本地时间列表转化为浮点数的秒来表示。

    2.语法

    time.mktime(t)

    3.参数

    t -- 结构化的时间或者完整的9位元组元素。

    4.返回值

    返回用秒数来表示时间的浮点数。

    5.实例

    import time
     
    print(time.localtime())
    # 传入localtime()返回的struct_time
    print(time.mktime(time.localtime()))
    # 传入9 元组数
    print(time.mktime((2020,12,10,8,52,30,3,345,0)))

    以上就是python中time.mktime()的转换,大家对于这种本地时间的转换方法,还可以学习对应的localtime函数,同时注意二者使用的区别,不要记混淆了。

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

    专题推荐:python timemktime
    品易云
    上一篇:pandas的连接函数concat()函数如何使用 下一篇:python中Array和DataFrame如何相互转换

    相关文章推荐

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

    全部评论我要评论

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

  • 取消发布评论
  • 

    Python学习网