Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35967
| References | <dfd18cf3-e2c0-4f0e-a4c1-a72924039a15@googlegroups.com> |
|---|---|
| Date | 2013-01-02 09:33 +0100 |
| Subject | Re: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? |
| From | Vlastimil Brom <vlastimil.brom@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1553.1357115628.29569.python-list@python.org> (permalink) |
2013/1/2 Victor Hooi <victorhooi@gmail.com>:
> 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.
>
> My question is, how should I omit elements from this tuple? And what is the expected behaviour when I do that?
>
> For example, (zero-index), element 6 is the day of the week, and element 7 is the day in the year, out of 366 - if I specify the earlier elements, then I shouldn't really need to specify these.
>
> However, the docs don't seem to talk much about this.
>
> I just tried testing putting garbage numbers for element 6 and 7, whilst specifying the earlier elements:
>
>> time.mktime((2012, 5, 5, 23, 59, 59, 23424234, 5234234 ,0 ))
>
> It seems to have no effect what numbers I set 6 and 7 to - is that because the earlier elements are set?
>
> How should I properly omit them? Is this all documented somewhere? What is the minimum I need to specify? And what happens to the fields I don't specify?
>
> Cheers,
> Victor
> --
> http://mail.python.org/mailman/listinfo/python-list
Hi,
if you initially have the time information as string, you might use
time.strptime(...) to extract this based on the supplied format; the
output of this function is usable as input for mktime, the remaining
fields are presumably handled consistently.
see:
http://docs.python.org/2/library/time.html#time.strftime
>>> time.strptime("2012-3-17", "%Y-%m-%d")
time.struct_time(tm_year=2012, tm_mon=3, tm_mday=17, tm_hour=0,
tm_min=0, tm_sec=0, tm_wday=5, tm_yday=77, tm_isdst=-1)
>>> time.mktime(time.strptime("2012-3-17", "%Y-%m-%d"))
1331938800.0
>>>
hth,
vbr
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Using mktime to convert date to seconds since epoch - omitting elements from the tuple? Victor Hooi <victorhooi@gmail.com> - 2013-01-02 00:01 -0800
Re: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? Vlastimil Brom <vlastimil.brom@gmail.com> - 2013-01-02 09:33 +0100
Re: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? Dave Angel <davea@dejaviewphoto.com> - 2013-01-02 09:06 -0500
Re: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? Roy Smith <roy@panix.com> - 2013-01-02 09:28 -0500
Re: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? Chris Angelico <rosuav@gmail.com> - 2013-01-03 01:51 +1100
Re: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? roy@panix.com (Roy Smith) - 2013-01-02 12:27 -0500
Re: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? Chris Angelico <rosuav@gmail.com> - 2013-01-03 04:34 +1100
Re: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? Dave Angel <d@davea.name> - 2013-01-02 12:44 -0500
Re: Using mktime to convert date to seconds since epoch - omitting elements from the tuple? Barry Scott <barry@barrys-emacs.org> - 2013-01-03 23:46 +0000
csiph-web