time:时间
时间戳(浮点数)
import time
print(time.time())
睡眠(秒)
import time
time.sleep(2)
给人看的
import time
print(time.strftime("%Y-%m-%d %H:%M:%S"))
结构化时间(数据类型是命名元组)
import time
print(time.gmtime())
将时间戳转换成字符串时间:
import time
print(time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime()))
将字符串时间转换成时间戳:
import time
print(time.mktime(time.strptime("2024-3-16 12:30:30", "%Y-%m-%d %H:%M:%S")))
time模块重点:
time.time()
time.sleep()
time.gmtime() / time.localtime() # 将时间戳转换成字符串时间
time.strftime("格式化", "结构化") # 将时间戳转换成字符串时间
time.strptime("字符串", "格式化") # 将字符串时间转换成时间戳
time.mktime()