我有一个脚本可以从 datetime 获取日期,以及从 whois 服务获取日期:
import time
from datetime import datetime
import whois
#date
url='testurl.com'
now = datetime.now()
date1 = datetime.strftime(nowstr,'%Y-%m')
#whois
domain = whois.whois(url)
datestr = domain.creation_date
date2 = datetime.strftime(datestr, '%Y-%m')
当我计算差异时:
diff = datetime.strptime(date1,'%Y-%m') - datetime.strptime(date2,'%Y-%m')
print diff
它给了我这样的输出:
5451 days, 0:00:00
如何获得年和月格式的输出(在我的情况下,14y 11m)?