码迷,mamicode.com
首页 > 编程语言 > 详细

Python:求时间差(天时分秒格式)

时间:2020-05-27 20:50:36      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:format   网络时间   result   time   orm   from   一个   form   pre   

输入一个10位的时间戳,求出时间差

def time_diff(timestamp):
	onlineTime = datetime.datetime.fromtimestamp(timestamp)
	localTime = datetime.datetime.now()
	result = localTime - onlineTime
	hours = int(result.seconds / 3600)
	minutes = int(result.seconds % 3600 / 60)
	seconds = result.seconds%3600%60
	print("当前网络时间:{0}".format(localTime))
	print("上次在线时间:{0}".format(onlineTime))
	print("{0}天{1}时{2}分{3}秒前在线".format(result.days,hours,minutes,seconds))

times = int(time.time())-80
time_diff(times)

运行效果:

当前网络时间:2020-05-27 18:00:03.393412
上次在线时间:2020-05-27 17:58:43
0天0时1分20秒前在线

Python:求时间差(天时分秒格式)

标签:format   网络时间   result   time   orm   from   一个   form   pre   

原文地址:https://www.cnblogs.com/51benpao/p/12975831.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!