Reed_Xia
Reed_Xia

Reputation: 1442

How to get the duration time in Python?

See my sample code:

import time

start_time_string = "2013-05-24 17:51:06"
end_time_string = "2013-05-24 17:59:33"

start_time_stamp = time.mktime(time.strptime(start_time_string, "%Y-%m-%d %H:%M:%S"))
start_time_struct = time.localtime(start_time_stamp)

end_time_stamp = time.mktime(time.strptime(end_time_string, "%Y-%m-%d %H:%M:%S"))
end_time_struct = time.localtime(end_time_stamp)

# what's the next step to get duration time, like x minute?

I read https://docs.python.org/2/library/time.html but don't find a method.

Thank you!

This question is closed, thanks so much to pjz and Robᵩ!

A perfect solution is posted in http://ideone.com/J8VwNl

Upvotes: 0

Views: 1961

Answers (1)

pjz
pjz

Reputation: 43057

You want to use the datetime module, not the time module.

Upvotes: 1

Related Questions