Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

datetime - Setting the system date in Python (on Windows)

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.

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.

And you can set them using either

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

or

os.system("date " + mm/dd/yy)

date.exe also appears to accept mm-dd-yy, 4-digit years, and probably other alternatives.

I prefer the latter for simplicity.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should be able to use win32api.SetSystemTime. This is part of pywin32.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...