On 9/13/2012 11:19 AM, Max wrote:
How do I set the time in Python?
If you look up 'time' in the index of the current manual, it directs you
to the time module.
"time.clock_settime(clk_id, time)
Set the time of the specified clock clk_id.
Availability: Unix.
New in version 3.3."
You did not specify *which* time to set, but ...
"time.CLOCK_REALTIME
System-wide real-time clock. Setting this clock requires appropriate
privileges.
Availability: Unix.
New in version 3.3."
Chris already suggested an approach for changing your process's idea of
time. However, setting time.timezone seems to have no effect
Also, is there any *direct* way to shift it?
If you mean time.clock_shift(clk_id, shift_seconds), no.
time.clock_settime(clk_id, time.clock_gettime(clk_id) + delta_seconds)
Note that any "indirect" methods may need complicated ways to keep
track of the milliseconds lost while running them.
Whay would a millisecond matter? System clocks are never synchronized to
official UTC time that closely without special hardware to receive time
broadcasts.
It even took around one
second in some virtual machine guest systems. So I'm hoping Python happens to
have the magic needed to do the job for me.
The above should be well under a second.
--
Terry Jan Reedy
--
http://mail.python.org/mailman/listinfo/python-list