[Tutor] Setting the system time

alan.gauld@bt.com alan.gauld@bt.com
Thu, 31 Jan 2002 17:14:35 -0000


> There are various ways to _get_ the system time
> >>> time1 = time.localtime(time.time())

> What is the way to _set_ a system time (to another value)?

I'm not sure Python has a module function for this 
- but based on past experience someone will find one 
somewhere!

However one thing to rememnber is that on most OSs this 
is an administrator or root privilege thing and so if 
your program doesn't run as root it won't work...

Assuming Python doesn't do it I guess you might be able 
to use os.system to do it. 

Certainly on DOS/Win 9x that would work with the 
"time" command.

On *nix you would use the "date" command as root.

Also be aware that on networks the time is often set 
on bootup from a central timeserver so setting it 
locally will only work until next bootup.

> I suppose I'll need mktime() for this as well?
> >>> print time.mktime(time1)
> 1012416968.0

I don't tink mktime will help here, it just creates a local 
'time object' within your program.

Alan g.