Using mktime to convert date to seconds since epoch - omitting elements from the tuple?

Dave Angel davea at dejaviewphoto.com
Wed Jan 2 09:06:51 EST 2013


On 01/02/2013 03:01 AM, Victor Hooi wrote:
> Hi,
>
> I'm using pysvn to checkout a specific revision based on date - pysvn will only accept a date in terms of seconds since the epoch.
>
> I'm attempting to use time.mktime() to convert a date (e.g. "2012-02-01) to seconds since epoch.
>
> According to the docs, mktime expects a 9-element tuple.

Actually, it expects a struct_time, but will work with a tuple.  The
easiest way to build a struct_time from your string would be using

time.strptime(), as suggested by Vlastimil.

> <snip>

The other problem is one of timezone. I would assume that svn would be
expecting all times to be in UTC, so to convert from struct_time in UTC
to seconds since epoch, you'd use calendar.timegm()
<http://docs.python.org/2/library/calendar.html#calendar.timegm>    See
the chart on http://docs.python.org/2/library/time







More information about the Python-list mailing list