time模块案例演示

案例01: 2008年8月8日20:08:08 往后88,888,888秒是哪天?星期几?

日期->时间戳(浮点数)->可以做数学运算

 

演示:

import time

# 构造日期的元组,元组必须是9位标准的

tuple01 = (2008, 8, 8, 20, 8, 8, 0, 0, 0)

# 把指定的日期转换为时间戳

chinese_time = time.mktime(tuple01)

print(time.localtime(chinese_time))

print(time.asctime(time.localtime(chinese_time)))

# 往后88888888

chinese_time += 88888888.0

# 输出结果

print(time.localtime(chinese_time))

print("结果:", time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(chinese_time)), end = "\t")

 

tule_weeb = ("星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日")

time.sleep(5) # 程序暂停5秒钟

print(tule_weeb[time.localtime(chinese_time)[6]])

 

执行结果:

C:\python\python.exe C:/python/demo/file3.py

time.struct_time(tm_year=2008, tm_mon=8, tm_mday=8, tm_hour=20, tm_min=8, tm_sec=8, tm_wday=4, tm_yday=221, tm_isdst=0)

Fri Aug  8 20:08:08 2008

time.struct_time(tm_year=2011, tm_mon=6, tm_mday=3, tm_hour=15, tm_min=29, tm_sec=36, tm_wday=4, tm_yday=154, tm_isdst=0)

结果: 2011-06-03 15:29:36        星期五

 

Process finished with exit code 0

 

注意:程序暂停

Time.sleep() 程序暂停多少秒

posted @ 2018-03-12 10:24  奶茶,我只要敌敌畏  阅读(252)  评论(0编辑  收藏  举报