datetime

Ian Kelly ian.g.kelly at gmail.com
Thu Sep 13 13:08:23 EDT 2012


On Thu, Sep 13, 2012 at 9:19 AM, Max <readmax at hushmail.com> wrote:
> How do I set the time in Python?

On what platform?  I don't know of any libraries for this, so it would
be a matter of making the necessary system calls (which is all that a
library would do anyway).

> Also, is there any *direct* way to shift it?

Only by changing the timezone setting.  Any method of offsetting the
system clock itself is going to involve at some level reading the
current value, adding or subtracting, and then setting the new value.

> Note that any "indirect" methods may need complicated ways to keep
> track of the milliseconds lost while running them. 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.

If you're concerned about individual seconds, then you probably should
do this in a low-level language like C.  Also, the clock is going to
drift naturally over time anyway.  How are you going to keep it in
sync if not with ntp?



More information about the Python-list mailing list