Convert date/time to unix timestamp?

andrew cooke andrew at acooke.org
Tue Feb 10 08:00:37 EST 2009


the python routines are a bit basic - you really have to think quite hard
about what you are doing to get the right answer.

in your case, you need to be clear what the timezone is for the datetime
you are using.  timezone info is optional (see the datetime documentation,
where it talks about "naive" and "aware" objects).

anyway, ignoring that, i think you need the very useful, but oddly
located, calendar.timegm().

andrew


Phillip B Oldham wrote:
> Is there a simple way to set a date/time and convert it to a unix
> timestamp? After some googling I found the following:
>
> t = datetime.time(7,0,0)
> starttime = time.mktime(t.timetuple())+1e-6*t.microsecond
>
> That seems like very long-winded. Is there an easier way? I've read
> the docs on the datetime and time modules, but nothing's jumping out
> at me.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>





More information about the Python-list mailing list