python实现修改,每过一秒修改系统时间往后面一天往后面 4小时

import datetime
import time
import win32api

# 获取当前系统时间
current_time = datetime.datetime.now()

# 计算每秒钟需要增加的时间量(这里设定为1天)
time_delta = datetime.timedelta(days=1)

while True:
    try:
        # 计算新的时间
        new_time = current_time + time_delta

        # 设置新的系统时间
        win32api.SetSystemTime(
            new_time.year,
            new_time.month,
            new_time.weekday(),
            new_time.day,
            new_time.hour,
            new_time.minute,
            new_time.second,
            0
        )

        # 输出修改后的日期
        print(f"系统日期已修改为:{new_time.date()}")

        # 更新当前时间
        current_time = new_time

        # 等待一秒钟
        time.sleep(2)

    except Exception as e:
        print(f"发生错误:{e}")
        break

这个是往后面四小时

import datetime
import time
import win32api

# 获取当前系统时间
current_time = datetime.datetime.now()

# 计算每秒钟需要增加的时间量(这里设定为4小时)
time_delta = datetime.timedelta(hours=4)

while True:
    try:
        # 计算新的时间
        new_time = current_time + time_delta

        # 设置新的系统时间
        win32api.SetSystemTime(
            new_time.year,
            new_time.month,
            new_time.weekday(),
            new_time.day,
            new_time.hour,
            new_time.minute,
            new_time.second,
            0
        )

        # 输出修改后的日期
        print(f"系统日期已修改为:{new_time.date()}")

        # 更新当前时间
        current_time = new_time

        # 等待一秒钟
        time.sleep(1)

    except Exception as e:
        print(f"发生错误:{e}")
        break

猜你喜欢

转载自blog.csdn.net/weixin_55008315/article/details/131527422