python 中 time 有三种格式:float,struct tuple(time.struct_time 或 datetime.datetime),str 常用的:float --> struct tuple: time.localtime( fl ...
python 中 time 有三种格式:
float,
struct tuple(time.struct_time 或 datetime.datetime),
str
常用的:
float --> struct tuple: time.localtime( float )
struct time tuple --> str: time.strftime(format, struct time tuple)
str --> struct time tuple: time.strptime(str, format)
struct time tuple --> float : time.mktime(struct time tuple)
struct time tuple --> datetime: datetime(*time_tuple[0:6])
float --> datetime: datetime.datetime.fromtimestamp( float )
datetime --> str: datetime.strftime(format, datetime)
str --> datetime: datetime.strptime(str, format)
datetime --> struct time tuple: datetime.timetuple()
Note:
time 是 float 为基础,小数点后是毫秒,整数部分是秒。(Java 是毫秒,所以,python_time*1000 == Java_time)
datetime 是int, 略去了毫秒部分。datetime tuple 少于 struct_time
1. 当前时间
2. 日期字符串--> 日期
3. 时间戳
>>> time.mktime(time.strptime(s,'%Y-%m-%d %H:%M:%S'))1450681288.0>>> int(time.time())
转:http://www.cnblogs.com/snow-backup/p/5063665.html
原标题:python 常用 time, datetime处理
关键词:python
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。