Skip to content
The Chat Archive
gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)

写一个电脑自动开关机的代码

  1. User

    写一个电脑自动开关机的代码

  2. Assistant

    import os import time

    def automatic_power_management(start_time, end_time): while True: current_time = time.strftime("%H:%M")

        if current_time == start_time:
            os.system("shutdown /s /f /t 0")  # 关机指令
        elif current_time == end_time:
            os.system("shutdown /r /f /t 0")  # 重启指令
        
        time.sleep(60)  # 每分钟检测一次时间
        
    

    设置每天的开关机时间,24小时制(例如 "HH:MM")

    start_time = "09:00" end_time = "18:00"

    automatic_power_management(start_time, end_time)