[Zope] How can I import DateTime into a script??

J. Cameron Cooper jccooper@rice.edu
Mon, 13 Aug 2001 10:54:43 -0500


>
> I am trying to create an Id based on the time of its creation.
>
> since I can not use the Pythons thime module I would like to use a 
> DateTime class.
>
>  
>
> However I stumbled trying to do so.
>
>  
>
> the following code:
>
> import DateTime
>
> t = DateTime.Time()
>
The constructor for DateTime makes a DateTime object of the current 
time. Try something like::

   t = DateTime()

If you want the Python 'time' module's floating point 
seconds-since-epoch format, you can say::

   secs = t.timeTime()

So of course, you could do something like this to get an id::

   id = `int(DateTime().timeTime())`

which makes a string our of an int out of a floating point number made 
from the current time. The string thing may or may not be necessary.

        --jcc
    (many types)