zoukankan      html  css  js  c++  java
  • python模块------time

    说明

    time模块提供各种时间相关的功能 与时间相关的模块有:time,datetime,calendar

    这个模块的功能不是适用于所有的平台 这个模块中定义的大部分函数是调用C平台上的同名函数实现

    time是python自带的模块,用于处理时间问题,提供了一系列的操作时间的函数

    用法

    1、time.sleep(secs)

    可以实现在python程序中的延时,单位为秒,并支持浮点数非整数秒的延时。例:

    import time
    
    for i in range(3):
        time.sleep(2)
        print("hello word")
    

    2、时间获取

    time.strftime("%Y-%m-%d %H:%M:%S")  #格式化时间
    time.time()#获得当前时间的时间戳
    

    实例

    1、创建以时间为名称的文件夹

    [root@node5801 test]# more 1.py 
    #!/usr/bin/python
    import time
    import os
    
    date = time.strftime("%Y-%m-%d")
    os.mkdir(date)
    [root@node5801 test]# python 1.py 
    [root@node5801 test]# ls
    1.py  2020-07-01
    

      

    官方文档:https://docs.python.org/3/library/time.html#time.struct_time

  • 相关阅读:
    1143 Lowest Common Ancestor (30)
    PAT 1135 Is It A Red-Black Tree
    PAT 1119 Pre- and Post-order Traversals
    1102 Invert a Binary Tree(25 分)
    PAT总结
    c++ getline的用法
    PAT 1049 Counting Ones (30)
    PAT 1022 Digital Library (30)
    java jar包
    NIO的理解
  • 原文地址:https://www.cnblogs.com/jinyuanliu/p/10481863.html
Copyright © 2011-2022 走看看