Time

kyosohma at gmail.com kyosohma at gmail.com
Mon May 14 10:09:40 EDT 2007


On May 14, 9:00 am, HMS Surprise <j... at datavoiceint.com> wrote:
> Thanks for posting. I sure am sorry that I wasted your time. I should
> have started the post stating I am using jython 2.2.3 and apparently
> it has no datetime module. But I will keep datetime in mind for future
> reference.
>
> Since I had no datetime I cobbled out the following. Seems to work
> thus far. Posted here for the general amusement of the list.
>
> Regards,
>
> jvh
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> from time import *
> s = '05/11/2007 1:23 PM'
> t = s.split()
> mdy = t[0].split('/')
>
> hrMn = t[1].split(':')
> if t[2] == 'PM':
>     hrMn[0] = int(hrMn[0]) + 12
>
> tuple =(int(mdy[2]), int(mdy[0]), int(mdy[1]), hrMn[0], int(hrMn[1]),
> 0,0,0,0)
> print tuple
>
> eTime = mktime(tuple)
> print 'eTime', eTime

Since jython works with Java, why not use Java's time/datetime
modules? Various links abound. Here are a few:

http://www.raditha.com/blog/archives/000552.html
http://www.xmission.com/~goodhill/dates/deltaDates.html
http://www.velocityreviews.com/forums/t149657-find-difference-in-datetime-variables.html

Maybe those will give you some hints.

Mike




More information about the Python-list mailing list