Am I doing this wrong? Why does this seem so clumsy (time, datetime vs. DateTime)

AggieDan04 danb_83 at yahoo.com
Sun Sep 20 15:13:54 EDT 2009


On Sep 19, 9:22 pm, Schif Schaf <schifsc... at gmail.com> wrote:
> The other day I needed to convert a date like "August 2009" into a
> "seconds-since-epoch" value (this would be for the first day of that
> month, at the first second of that day).
>
> In Python, I came up with this:
>
> ~~~~
> #!/usr/bin/env python
>
> import datetime
> import time
>
> time_in_sse = time.mktime(
>     datetime.datetime(2009, 8, 1).timetuple()
> )

(datetime.datetime(2009, 8, 1) - datetime.datetime(1970, 1, 1)).days *
86400

But still, this should be part of the datetime class.



More information about the Python-list mailing list