time模块,计算时间差
计算当前时间与所输入的时间的时间差
#1 计算当前时间的时间戳时间
t_now = time.time() # 计算以前的时间的时间戳时间
t_before = input('请输入时间(例如:2000-01-01 01:01:01)>>>')
t_be = time.strptime(t_before,'%Y-%m-%d %H:%M:%S') # 格式化时间 转 结构化时间
t_b = time.mktime(t_be) #结构化时间 转 时间戳时间 # 计算时间戳时间差
t_dif = t_now - t_b
# print(t_dif) # 时间戳时间转格式化时间
m_d = time.gmtime(t_dif)
# print(m_d) #时间对象(结构化时间) 能通过 .属性名 来获取对象中的值
print('现在距离您输入的时间已经过去了%s年%s月%s天%s小时%s分钟%s秒' %
(m_d.tm_year-1970,m_d.tm_mon,m_d.tm_mday,m_d.tm_hour,m_d.tm_min,m_d.tm_sec))
time模块,计算时间差的更多相关文章
- python计算时间差
前言 之前写代码都是看打印的初始和结束时间然后自己算间隔时间,感觉总是不方便,这不符合python的优雅简洁,于是去寻找简便之道. 方法 time模块计算时间差 import time s_time ...
- datetime 计算时间差
计算时间差: .date() # 格式化 .timedelta() # 时间差 import datetime # 今天 today = datetime.datetime ...
- python计算时间差的方法
本文实例讲述了python计算时间差的方法.分享给大家供大家参考.具体分析如下: 1.问题: 给定你两个日期,如何计算这两个日期之间间隔几天,几个星期,几个月,几年? 2.解决方法: 标准模块date ...
- python使用datetime模块计算各种时间间隔的方法
python使用datetime模块计算各种时间间隔的方法 本文实例讲述了python使用datetime模块计算各种时间间隔的方法.分享给大家供大家参考.具体分析如下: python中通过datet ...
- Android计算时间差
想要写个根据消耗时长来确定开始结束时间的小工具,发现Android处理时间上有点累,可能是我没找到合适的方法吧,先把我的解决办法贴出来,有好的解决方法还希望提醒一下: 1.根据时间字符串获取毫秒数 p ...
- 【转载】c/c++在windows下获取时间和计算时间差的几种方法总结
一.标准C和C++都可用 1.获取时间用time_t time( time_t * timer ),计算时间差使用double difftime( time_t timer1, time_t time ...
- C#计算时间差值
/// <summary> /// 计算时间差值 /// </summary> /// <param name="DateTime1">< ...
- 登录超时自动退出,计算时间差-b
// 此方法适用于所有被创建过的controller,且当前controller生命周期存在,如有错误的地方望大神斧正 // 说一下我们的需求和实现原理,需求:在点击home键退出但没有滑飞它,5分 ...
- python分页和session和计算时间差
分页 #!/usr/bin/env python # -*- coding:utf-8 -*- class Pagenation: def __init__(self,current_page,all ...
随机推荐
- 服务器 apache配置https,http强制跳转https(搭建http与https共存)
公司linux服务器上的nginx的已经改成https了,现在还剩下一个windows云服务器没配置. 环境 windows wampserver2.5 64位 1.腾讯云申请的ssl 包含三个文件: ...
- 2018 Multi-University Training Contest 4
累惹. B. Harvest of Apples 题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6333 题意:求∑(i=0,m) C(n,m). 分 ...
- 使用过Memcache缓存吗?如果使用过,能够简单描述下其工作原理吗?
Memcache是把所有数据保存在内存中,采用hash表的方式,每条数据由key和value组成,每个key独一无二的.Memcache采用LRU算法逐渐把过期数据清除掉.
- [Virus Analysis]恶意软件分析(二)玩出花的批处理(中)
本文作者:i春秋作家——Sp4ce 0×01上一篇文章部分 首先是文件目录 整理后的目录 整理前的部分文件代码 update.bat %%Q %%Q %%Q %%Q %%Q %%Q %%Q %%Q % ...
- 解决spring的java.lang.IllegalArgumentException异常
解决办法是: 右击项目 ---> properties --->project facets : 修改JDK版本,需要将1.8 降为1.7版本.
- 【LeetCode】390. 消除游戏
题目 给定一个从1 到 n 排序的整数列表. 首先,从左到右,从第一个数字开始,每隔一个数字进行删除,直到列表的末尾. 第二步,在剩下的数字中,从右到左,从倒数第一个数字开始,每隔一个数字进行删除,直 ...
- android view知识点 总结
DecorView : http://www.jianshu.com/p/5aa96683d0dc 安卓事件分发机制: http://blog.csdn.net/guolin_blog/article ...
- 使用seek()方法报错:“io.UnsupportedOperation: can't do nonzero cur-relative seeks”错误的原因
在使用seek()函数时,有时候会报错为 “io.UnsupportedOperation: can't do nonzero cur-relative seeks”,代码如下: >>& ...
- hadoop2.x 安装配置
hadoop2.x在系统架构上与hadoop1.x有很大的变化 原文地址: http://www.ibm.com/developerworks/cn/opensource/os-cn-hadoop-y ...
- Maven-pom.xml文件报错 Plugin execution not covered by lifecycle configuration
问题: Eclipse中新导入的项目pom.xml文件报错: Plugin execution not covered by lifecycle configuration: org.jacoco:j ...