您可以使用精彩的dateutil模块及其relativedelta类:
import datetimeimport dateutil.relativedeltadt1 = datetime.datetime.fromtimestamp(123456789) # 1973-11-29 22:33:09dt2 = datetime.datetime.fromtimestamp(234567890) # 1977-06-07 23:44:50rd = dateutil.relativedelta.relativedelta (dt2, dt1)print "%d years, %d months, %d days, %d hours, %d minutes and %d seconds" % (rd.years, rd.months, rd.days, rd.hours, rd.minutes, rd.seconds)# 3 years, 6 months, 9 days, 1 hours, 11 minutes and 41 seconds
它不需要数周,但是添加起来应该并不难。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)