Time and date operation

H

huisky

Hi everyone,

Could you anybody shed lights to me? Say I have two dics.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']})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.

thanks in advance

Huisky
 
C

Chris Rebert

Hi everyone,

Could you anybody shed lights to me? Say I have two dics.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']})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
 
C

Chris Rebert

-----Original Message-----
From: (e-mail address removed) [mailto: (e-mail address removed)]
Sent: 2010年11月23日 19:12
To: huisky
Cc: (e-mail address removed)
Subject: Re: Time and date operation

Hi everyone,

Could you anybody shed lights to me? Say I have two dics.
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']})
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
Hi,

Thanks. I'm wondering is datetime.datetime objects able to read 'Dec', for example?

Yes. Use the %b format directive when calling datetime.datetime.strptime().
http://docs.python.org/library/datetime.html#datetime.datetime.strptime
http://docs.python.org/library/time.html#time.strftime

Cheers,
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top