Python:求时间差(天时分秒格式)
2024-09-01 05:09:36
传入一个时间戳,以天时分秒格式打印出时间差
输入一个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秒前在线
最新文章
- 【WCF】使用“用户名/密码”验证的合理方法
- Java类变量和成员变量初始化过程
- mac 终端常用命令
- 知方可补不足~row_number,rank,dense_rank,ntile排名函数的用法
- Android中的五大布局和logcat打印日志
- maven使用入门(pom)
- 绑定本地Service并与之通信-----之二
- Js验证userAgent是否来自手机端
- delphi数字签名验证及能够获取数字签名文件信息(利用wintrust.dll的导出函数,翻译一下)
- jquery mobile左右滑动切换页面
- Asp.net网站的简单发布
- Hibernate一级缓存(基于查询分析)
- codeforces 8c Looking for Order
- 4.ElasticSearch的基本api操作
- Spark2.X管理与开发
- 【洛谷P1429】平面最近点对
- udp用户数据报协议
- JVM内存初学 堆、栈、方法区
- 第一个Sprint冲刺成果
- javascript深度克隆对象