[Tutor] Class, input

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Mon Aug 23 03:35:01 CEST 2004



On Sun, 22 Aug 2004, jason hochstein wrote:

> Danny, the date stamp is more what I am confused about. I understand
> "import time". Is there an "import date"?


Hi Jason,

Although there is no 'date' module in the Standard Library, there are both
the 'time' and 'datetime' modules:

    http://www.python.org/doc/lib/module-datetime.html
    http://www.python.org/doc/lib/module-time.html

These two modules that might be applicable in forming a "timestamp",
although I think you may just need functions in the 'time' module.  The
'datetime' module adds more features, like date arithmetic, but you might
not need this.  Can't hurt to browse through it, of course.  *grin*


But let's clarify something: what kind of timestamp are you looking for?
If you're referring to the Unix timestamp --- the number of seconds that
have passed after January 1, 1970 --- then the time.time() function is
probably what you're looking for:


###
>>> import time
>>> time.time()
1093224607.5026591
>>> time.time()
1093224610.4942141
###

Here, we see that about three seconds passed between the calls to
time.time().  time.time() gives different results, depending on at what
point you call it.

If you need something more human readable, like a string, then you can use
time.strftime(); the documenation has a good example of how to use
time.strftime.


If you have more questions, please feel free to ask.  Good luck to you!



More information about the Tutor mailing list