[Tutor] Question on Time calculations.

montana montana@buc99.bsd.st
Thu Jan 16 18:10:03 2003


Magnus wrote:
If you look through the mxDateTime docs, that you got a link
to, I'm sure you will find more robust solutions. If you know
that time is entered as "%m.%d.%y %H%M", you could do

>>> stime = "12.31.2002 1259"
>>> date, time = stime.split()
>>> month, day, year = map(int,date.split('.'))
>>> hour, min = map(int,[time[:-2], time[-2:]])
>>> print DateTime.DateTime(year, month, day, hour, min, 0)
2002-12-31 12:59:00.00

This is a few more lines of code, but it's certainly more robust.
It will handle a much larger span in time, and it doesn't realy
on particular locale settings etc.

But then how do you get the date parsed?

Parser.DateTimeFromString does not like "2002-12-31 12:59:00.00" when I enter that.  I used asctime to put it in a format that the parser would like.

Thanks.
SA
:)