用來練手的python 練習題,原鏈接 : python練習實例9
題干 :
暫停兩秒輸出,并格式化當前時間。
import time,datetimeTIME = datetime.datetime.now()
print(TIME.strftime("%Y.%m.%d %H-%M-%S"))
time.sleep(2)
TIME = datetime.datetime.now()
print(TIME.strftime("%Y.%m.%d %H-%M-%S"))
輸出結果如下:
輸出當前時間的格式化輸出比較特別,用的是%Y,%m,%d 年月日,以及%H %M %S 小時,分鐘,秒。