简体   繁体   English

如何在Windows上使用python更改系统日期

[英]How to change a system date with python on windows

I'm trying to change system date, adding 8 days to current date. 我正在尝试更改系统日期,将当前日期添加8天。 But unfortunately I am receiving 但不幸的是我收到了

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

My code is: 我的代码是:

import datetime
import win32api

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

So I need to turn my 'tomorrow' valuable into a string with 8 arguments. 所以我需要把我的'明天'贵重变成一个带有8个参数的字符串。 or maybe there is a better function than SetSystemTime. 或者可能有比SetSystemTime更好的功能。 Do you have any ideas? 你有什么想法?

In reference to the method win32api.SetSystemTime all the arguments must be of type integer. 在参考方法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)

产量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM