Question: Convert datetime to long number

Tim Peters tim_one at email.msn.com
Sun May 25 18:19:51 EDT 2003


[Gerrit Holl]
> ...
> Is 1053828152.54 a timestamp?

Yes.

> ...
> That would mean that
>
>     float(dt.strftime("%s")) + dt.microsecond/1000000.0
>
> does what John asked:
>
>  22 >>> x, a = datetime.now(), time.time()
>  23 >>> float(x.strftime("%s")) + x.microsecond/1000000.0, a
> (1053893218.302195, 1053893218.302245)
>
> Or am I mistaken here?

Seemingly relying on a platform extension:  %s isn't a standard format code
for strftime:

    http://www.python.org/dev/doc/devel/lib/module-time.html#l2h-1673

If strftime("%s") does something on your platform (it doesn't on mine),
that's a platform-specific extension to standard C strftime behavior.  John
may or may not see the same thing on his box.






More information about the Python-list mailing list