Python equivalent of settimeofday()?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Narendra C. Tulpule

    Python equivalent of settimeofday()?

    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.
  • Jeff Epler

    #2
    Re: Python equivalent of settimeofday()?

    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!

    Comment

    • Peter Hansen

      #3
      Re: Python equivalent of settimeofday()?

      "Narendra C. Tulpule" wrote:[color=blue]
      >
      > 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()?[/color]

      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

      Comment

      Working...