天天看點

kobe - 時間,日期,回顧了for循環記錄代碼運作了多久

# 時間
# 1970年1月1日 到現在一共過了多少秒
# import time
# t1 = time.time()
# print(t1)
# # 睡眠兩秒
# time.sleep(2)
# t2 = time.time()
# # print(t2)
# # 本地時間
# localtime = time.localtime()
# print(localtime)
# # year 年 month 月份  day日 16  hour  11點  minute32分鐘  second9秒  week of day 6 yday 47 isdst 0
# # 夏令時
# # 轉成我們平時看時間的格式
# print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))
# # 遊戲時間  幾點幾分
# print(time.strftime("%a %b %H:%M",time.localtime()))
# print(time.strftime("%A %B %H:%M",time.localtime()))

# 月曆  calendar
import calendar
# 月月曆
cal = calendar.month(202,2)
print(cal)

# 年月曆
cal = calendar.calendar(202)
print(cal)

with open("月曆.txt", "w") as  f:
    f.write(cal)


           

記錄代碼運作了多久

import time
# 記錄了代碼運作了多久
# 計算1-100的和
t1 = time.time()
n=0
for a in range(1000001):
    n=n+a
    print(n)
t2 = time.time()
print("代碼運作的時間為%f秒"%(t2-t1))

           

繼續閱讀