How do I set the hardware clock with Python on embedded Linux systems?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
This uses
ioctl
to set the hardware clock as requested (but not the system clock). It avoids extra processes but is more involved. I am usingpytz
anddateutil
to handle local/utc conversions. Feel free to use the code (3-clause BSD License). Get the clock withget_hwclock()
and set it withset_hwclock()
...An updated version on Ubuntu 16.04:
Important note: you may need to change the time/date settings to manually set (
set-ntp false
) or else it will immediately change it back to the current time.hwclock -w
sets the hardware clock based on the current system time (set bydate
)It is required that
date
&hwclock
are run assudo
as well.Use Python's os.system function to call the hwclock command.
Probably no easy way other than doing an os.system() call.
or using the 'date' command
or if you are dying to do some c coding, wrapping the system calls with swig... but I think that would be more work than its worth.