[Tutor] Date and Time questions
Paul De Luca
pdeluca@sia.net.au
Tue, 10 Jul 2001 02:45:00 +1000 (EST)
>From the docs I managed to work out your problem. It was a bit
complicated, I just looked for the function that provided output, then
find out what data it needed, then looked for a function that provided
that etc. Running Linux and using the date command with its string
formatting options made this seem a bit familiar too.
[pd@localhost pd]$ python
Python 2.0 (#1, Apr 11 2001, 19:18:08)
[GCC 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)] on linux-i386
Type "copyright", "credits" or "license" for more information.
>>> import time
>>> epoch = time.time()
>>> localtime = time.localtime(epoch)
>>> timeString = time.strftime('%Y%m%d_%H:%M', localtime)
>>> print timeString
20010710_02:25
>>>
Here I returned the string as year|month|day_HourIn24hrFormat|Minute|
If it looks a bit foreign read through the time module a few times, and
you should get it. Epoch - the time in seconds past a set date. On UNIX
machines this is Jan 1 1970 at 00:00
There is also a bit of info on the different ways time is measured at the
beginning of the module docs.
On Mon, 9 Jul 2001, Schmidt, Allen J. wrote:
> I have looked around for things that deal with Date and Time.
> All I want to do is be able to assign a date/time value to a variable. Like
> 20010709_18:05.
> Does not need to be a date object just a text string that I can use to drop
> into a database table or use in other ways.
>
> The date time stuff seems a bit overly complicated. Any tips or pointers to
> online resources I may have missed.
>
> Thanks
>
> Allen
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------------------
Paul De Luca
Email: pdeluca@sia.net.au
Ph: 0414 225 561
-------------------------