【问题标题】:How to change a system date with python on windows如何在 Windows 上使用 python 更改系统日期
【发布时间】:2019-08-28 14:26:04
【问题描述】:

我正在尝试更改系统日期,将当前日期添加 8 天。但不幸的是我收到了

TypeError: SetSystemTime() takes exactly 8 arguments (1 given)

我的代码是:

import datetime
import win32api

now = datetime.datetime.now()
print (now)
tomorrow = now + datetime.timedelta(days = 8)
print (tomorrow)
win32api.SetSystemTime(tomorrow)

所以我需要将我的“明天”值变成一个包含 8 个参数的字符串。或者也许有比 SetSystemTime 更好的功能。你有什么想法吗?

【问题讨论】:

标签: python


【解决方案1】:

在引用win32api.SetSystemTime 方法时,所有参数都必须是整数类型。

import datetime
import win32api

now = datetime.datetime.now()
print (now)
tomorrow = now + datetime.timedelta(days = 8)
print (tomorrow)

year = int(tomorrow.year)
month = int(tomorrow.month)
# Return the day of the week as an integer, where Monday is 0 and Sunday is 6.
dayOfWeek = int(tomorrow.weekday())
day = int(tomorrow.day)
hour = int(tomorrow.hour)
minute = int(tomorrow.minute)
second = int(tomorrow.second)
millseconds = int((tomorrow.microsecond)/1000)

win32api.SetSystemTime(year, month , dayOfWeek , day , hour , minute , second , millseconds)

【讨论】:

    猜你喜欢
    • 2015-01-10
    • 2022-08-17
    • 2011-03-17
    • 2012-03-31
    • 1970-01-01
    • 2013-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多