1 Star 0 Fork 1

thinking01 / py_notify_linkong

forked from bobshi / py_notify_linkong 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
time_util.py 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
bobshi 提交于 2013-09-05 22:52 . init commit,which works fine at linux
import time;
ISOTIMEFORMAT='%Y-%m-%d %X';
def ISOString2Time(s):
'''
convert a ISO format time to second
from:2006-04-12 16:46:40 to:23123123
把一个时间转化为秒
'''
return time.strptime( s, ISOTIMEFORMAT )
def Time2ISOString( s ):
'''
convert second to a ISO format time
from: 23123123 to: 2006-04-12 16:46:40
把给定的秒转化为定义的格式
'''
return time.strftime( ISOTIMEFORMAT, time.localtime( float( s ) ) )
def dateplustime( d, t ):
'''
d=2006-04-12 16:46:40
t=2小时
return 2006-04-12 18:46:40
计算一个日期相差多少秒的日期,time2sec是另外一个函数,可以处理,3天,13分钟,10小时等字符串,回头再来写这个,需要结合正则表达式。
'''
return Time2ISOString( time.mktime( ISOString2Time( d ) )+time2sec( t ) )
def dateMinDate( d1, d2 ):
'''
minus to iso format date,return seconds
计算2个时间相差多少秒
'''
d1=ISOString2Time( d1 )
d2=ISOString2Time( d2 )
return time.mktime( d1 )-time.mktime( d2 )
def getCurrentTime():
return Time2ISOString(time.time());
1
https://gitee.com/thinking01/py_notify_linkong.git
git@gitee.com:thinking01/py_notify_linkong.git
thinking01
py_notify_linkong
py_notify_linkong
master

搜索帮助