Python:time, strftime和strptime
2008-02-13 11:31
405 查看
最常用的time.time()返回的是一个浮点数,单位为秒。但strftime处理的类型是time.struct_time,实际上是一个tuple。strptime和localtime都会返回这个类型。
>>> import time
>>> t = time.time()
>>> t
1202872416.4920001
>>> type(t)
<type 'float'>
>>> t = time.localtime()
>>> t
(2008, 2, 13, 10, 56, 44, 2, 44, 0)
>>> type(t)
<type 'time.struct_time'>
>>> time.strftime('%Y-%m-%d', t)
'2008-02-13'
>>> time.strptime('2008-02-14', '%Y-%m-%d')
(2008, 2, 14, 0, 0, 0, 3, 45, -1)
>>> import time
>>> t = time.time()
>>> t
1202872416.4920001
>>> type(t)
<type 'float'>
>>> t = time.localtime()
>>> t
(2008, 2, 13, 10, 56, 44, 2, 44, 0)
>>> type(t)
<type 'time.struct_time'>
>>> time.strftime('%Y-%m-%d', t)
'2008-02-13'
>>> time.strptime('2008-02-14', '%Y-%m-%d')
(2008, 2, 14, 0, 0, 0, 3, 45, -1)
相关文章推荐
- Python:time, strftime和strptime
- 【python】详解time模块功能asctime、localtime、mktime、sleep、strptime、strftime、time等函数以及时间的加减运算
- Python中time, strftime和strptime
- Python time strftime()方法
- Python 常用函数time.strftime()简介
- Python time 函数time.strftime()简介
- python time strftime()
- Python time strptime()方法
- python使用 time.strftime() 命名文件名包含当前时间
- python常用函数 time.strftime
- Python time strftime()方法
- 【python】time和datetime的strptime不是线程安全的!
- Python 常用函数time.strftime()简介
- Python time strftime()方法
- Python time strftime()方法
- Python 常用函数time.strftime()简介
- Python time strptime()方法
- Python 常用函数time.strftime()简介
- python---到指定https地址下载图片验证码,https,urllib2,urllib,time,os,ssl
- python标准库之fnmatch,dis,timeit