Question: Convert datetime to long number
Gerrit Holl
gerrit at nl.linux.org
Sun May 25 05:56:03 EDT 2003
Gerrit Holl schreef op zondag 25 mei om 11:41:57 +0000:
> > >>> x=datetime.utcnow(); a=time.time()
> > >>> x,a
> > (datetime.datetime(2003, 5, 25, 2, 2, 32, 540000), 1053828152.54)
> > >>>
> >
> > what function f I can apply to x such that f(x) will return 1053828152.54 ?
>
> You can use the strftime method, and pass "%s" as entry:
>
> datetime.datetime.utcnow().strftime("%s")
>
> Note that strftime returns an int, not a float.
Note:
you may want to subclass datetime. This only works as of python 2.3b2,
because this bug was fixed on May, 17th:
http://sourceforge.net/tracker/index.php?func=detail&aid=720908&group_id=5470&atid=105470
I noticed this when I tried to subclass datetime to create a totimestamp()
method.
yours,
Gerrit.
--
40. He may sell field, garden, and house to a merchant (royal agents)
or to any other public official, the buyer holding field, house, and
garden for its usufruct.
-- Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
http://www.sp.nl/
More information about the Python-list
mailing list