python time模块

import time
time.sleep(100)
print(time.time())

print(time.strftime("%Y-%m-%d %a %H:%M:%S")) #year month day HOUR MINUTE SECOND
print(time.strftime("%Y/%m/%d %H:%M:%S")) #year month day HOUR MINUTE SECOND
print(time.strftime("%m-%d %H:%M:%S")) #year month day HOUR MINUTE SECOND
print(time.strftime("%H:%M:%S")) #year month day HOUR MINUTE SECOND
print(time.strftime("%H:%M")) #year month day HOUR MINUTE SECOND


struct_time = time.localtime()
print(struct_time)
print(struct_time.tm_year)

import time
# 时间戳和结构化时间
t = time.time()
print(t)
print(time.localtime(3000000000))
print(time.gmtime(t))

print(time.mktime(time.localtime()))

print(time.strptime('2000-12.31','%Y-%m.%d'))
print(time.strftime('%m/%d/%Y %H:%M:%S',time.localtime(3000000000)))

print(time.asctime())
上一篇:python – 将日期转换为小时


下一篇:python基础教程:if条件判断