python实现计算某一时间距离现在的天数

[code lang=”python”]
def get_time_difference(time) :
ltime=time.localtime(time)
timeStr = time.strftime(“%Y-%m-%d”, ltime)
nowdate = time.strftime(“%Y-%m-%d”)
#print datetime.datetime(nowdate)
(y1,m1,d1) = map(int, (time.strftime(“%Y”, ltime),time.strftime(“%m”, ltime),time.strftime(“%d”, ltime)));
d1 = datetime.datetime(y1, m1, d1)
(y2,m2,d2) = map(int, (time.strftime(“%Y”), int(time.strftime(“%m”)), time.strftime(“%d”)));
d2 = datetime.datetime(y2,m2,d2)
return (d2 – d1).days
[/code]

发表评论

您的电子邮箱地址不会被公开。