為了在規定時間內實現電腦關機,我使用python編寫了幾行代碼,最簡單的實現了關機操作,后續再進行其它功能的添加(操作頁面,取消等)
import os,time #獲取命令行輸入的關機時間 input_time = str(input("請輸入關機時間:")) #轉換成時間戳 time1 = time.strptime(input_time,"%Y-%m-%d %H:%M:%S") time2 = int(time.mktime(time1)) #獲取當前系統時間時間戳 now = int(time.time()) #計算電腦關機的等待時間 d = time2 - now print("距關機還有%d秒" %d) os.system('shutdown -s -t %d' %d)