Python equivalent of settimeofday()?

  • Thread starter Narendra C. Tulpule
  • Start date
N

Narendra C. Tulpule

Hi,
do you know how (or if) I can set time on a system using Python?
i.e. is there an equivalent of the shell's 'date -s' or the system
call settimeofday()?
Thanks -
-- Naren.
 
J

Jeff Epler

I don't think anybody's exposed it to Python yet. However, this would
be an easy thing to write in C, SWIG, Pyrex, or ctypes. Pick one and
get your feet wet!
 
P

Peter Hansen

Narendra C. Tulpule said:
do you know how (or if) I can set time on a system using Python?
i.e. is there an equivalent of the shell's 'date -s' or the system
call settimeofday()?

Maybe some variation on this?

import os,time

def settimeofday(tt):
ts = time.ctime(tt)
os.system("/sbin/hwclock --set '--date=%s'"% ts)
os.system("/sbin/hwclock --hctosys")


??

Note the final line, which retrieves the time from the hardware so the
system clock is also updated.

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top