以Python(在Windows上)设置系统日期 [英] Setting the system date in Python (on Windows)
问题描述
似乎有很多包用于获取/格式化当前日期,或从现在开始查找日期n个时间间隔。但是我必须忽略一个简单的方法来设置日期(比如Windows的date.exe)在Python中。
There appears to be many packages for getting/formatting the current date, or finding out the date n time intervals from now. But I must be overlooking the existence of a simple method to set the date (like Windows' date.exe) in Python.
这个函数是否存在?我在Google上找不到任何东西,python文档(datetime,time,os等)或堆栈溢出。 TIA。
Surely such a function exists? I've been unable to find anything on Google, the python docs (datetime, time, os, etc) or stack overflow. TIA.
编辑:总而言之,页面告诉你如何获取他们。
edit: To summarize,this page tells you how to get them.
您可以使用
win32api.SetSystemTime(year,month,dayOfWeek,day,hour,minute,second,millseconds)
或
os.system("date " + mm/dd/yy)
date.exe也似乎接受mm-dd-yy,4位数年份,还有其他替代方案。
date.exe also appears to accept mm-dd-yy, 4-digit years, and probably other alternatives.
我更喜欢后者为了简单起见。
I prefer the latter for simplicity.
推荐答案
您应该可以使用 win32api.SetSystemTime 。这是 pywin32 的一部分。
You should be able to use win32api.SetSystemTime. This is part of pywin32.
这篇关于以Python(在Windows上)设置系统日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!