Question: Convert datetime to long number

Gerrit Holl gerrit at nl.linux.org
Mon May 26 05:31:39 EDT 2003


I wrote:
> >  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?

Tim Peters schreef op maandag 26 mei om 00:27:07 +0000:
> 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.

Ah... thanks. I never knew that %s was platform-specific on my system; as
are, apparantly, %C, %D, %e, %E, %F, %g, %G, %h, %k, %l, %n, %O, %P, %r,
(%s), %R, %t, %T, %u, %V, %z. That's really a lot... but it's clear now.

Actually, those are almost all extensions that can be constructed with
the other format characters:

http://www.opengroup.org/onlinepubs/7908799/xsh/strftime.html

I think only %p, %u, %s can't be easily constructed with the others...

 22 >>> print time.strftime(''.join(["%s %%%s\t" % (c,c) for c in string.letters]))
a Mon   b May   c Mon May 26 11:30:32 2003      d 26    e 26    f %f    g 03    h May   i %i    j 146   k 11    l 11    m 05    n
        o %o    p AM    q %q    r 11:30:32 AM   s 1053941432    t               u 1     v %v    w 1     x 05/26/03      y 03    z +0200       A Monday        B May   C 20    D 05/26/03      E %E    F 2003-05-26    G 2003  H 11    I 11    J %J    K %K    L %L    M 30 N %N     O %O    P am    Q %Q    R 11:30 S 32    T 11:30:32      U 21    V 22    W 21    X 11:30:32      Y 2003  Z CEST

Only %f, %i, %o, %q, %v, %E, %J, %K, %L, %N, %O and %Q are undefined here...

yours,
Gerrit.

-- 
165. If a man give to one of his sons whom he prefers a field, garden,
and house, and a deed therefor: if later the father die, and the brothers
divide the estate, then they shall first give him the present of his
father, and he shall accept it; and the rest of the paternal property
shall they divide. 
        -- 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