Time and date operation

Chris Rebert clp2 at rebertia.com
Tue Nov 23 13:11:33 EST 2010


On Tue, Nov 23, 2010 at 9:47 AM, huisky <huisky at gmail.com> wrote:
> Hi everyone,
>
> Could you anybody shed lights to me? Say I have two dics.
>>>> cstart
> defaultdict(<type 'int'>, {15424: ['Dec', '6', '18:57:40'], 552:
> ['Dec', '7', '09:31:00'], 15500: ['Dec', '6', '20:17:02'], 18863:
> ['Dec', '7', '13:14:47'], 18291: ['Dec', '6', '21:01:17'], 18969:
> ['Dec', '7', '14:28:42'], 18937: ['Dec', '7', '14:21:34']})
>>>> ccompl
> defaultdict(<type 'int'>, {15424: ['Dec', '6', '19:42:55'], 18291:
> ['Dec', '6', '21:01:28'], 15500: ['Dec', '6', '20:26:03'], 18863:
> ['Dec', '7', '13:24:07']})
>
> and I need to calculate the difference time if the key value is the
> same in both dics.

Create datetime.datetime objects. Subtract one from another and you'll
get a datetime.timedelta object representing the difference between
them.
The fine manual: http://docs.python.org/library/datetime.html#datetime-objects

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list