python time 转换&运算tips
2014-10-04 15:24
369 查看
我们有几个以类似 2010.11.03.23.59 形式表示的字符串时间 想要进行一些运算 下面是一种简单的方法 点到为止 首先当然是
import time 1time_str = "2010.11.03.23.59" #定义一个format模板 format = "%Y.%m.%d.%H.%M" #分别对应 2010.11.03.23.59的各个字段 time_int = int(time.mktime(time.strptime(time_str,format))) #time.strptime是根据format转换time_str为一种python内部的tuple形式 #time.mktime根据tuple生成用秒表示的时间 带小数的 #int就是取整 毫秒在这里没有意义 然后尽情地进行邪恶的运算吧! #反向的话 1time_str = time.strftime(format, time.localtime(time_int))
相关文章推荐
- 不在WHERE子句中使用如ExitTime>GETDATE() - 10的日期运算语句大幅优化性能
- python time,datetime,string转换
- 已知s="(XYZ)+*",t="(X+Z)*Y",利用联接,求子串和转换等基本运算,将s转化为t
- ]python time, datetime, string, timestamp相互转换
- python--datetime&time
- python整理十八——datetime与time之间的转换
- python2《=》python3 某些库函数互相转换的个人总结 =>持续更新
- Python datetime / time 转换
- [python]用eval强制将字符串转换为字典变量时候出错:NameError: name 'null' is not defined[python]用eval函数 字符串转dict
- python之time&datetime
- python datatime 时区转换
- byte数组转float实现与byte转换其它类型时进行&运算原理
- Python Date & Time
- python中time类型,datetime类型的关系与互相转换
- Python 远程操作&文本转换excel
- Python快速学习03:运算 & 缩进和选择
- “yyyymmddhhmiss"、tm、time_t、ASN1_TIME 之间的类型转换
- python(3)methods & tips~
- Python中的数字运算及相关转换
- <Python一下>Time操作