I have a DATETIME field in SQL. Its content is: 2012-08-26 13:00:00
I want to know how much time has passed from that date until now.
In Python 2.7, it's easy:
import time,datetime
start = datetime.datetime.strptime('2012-08-26 13:00:00', '%Y-%m-%d %H:%M:%S')
end = datetime.datetime.now()
delta = start - end
print delta
But I have a web server running Python 2.4. In Python 2.4 strptime is not in the datetime module. I can't figure out how to accomplish the same thing in 2.4.
time.strptime is in Python 2.4. It returns a time tuple, which can be then converted to a datetime as shown below.
start = time.strptime('2012-08-26 13:00:00', '%Y-%m-%d %H:%M:%S')
start = datetime.datetime(*start[:6])
在python 2.4中, strptime()
函数位于time
模块中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.