|
由于要用到时间模块,为了下次不用去翻文档,这里也简单记录一下:直接一个脚本看输出:
1
2
3
4
5
6
7
8
9
| import time
print time.time()
print time.localtime(time.time())
print time.strftime('%Y-%m-%d', time.localtime())
print time.strftime('%y-%m-%d', time.localtime())
print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
print time.strftime('%Y-%m-%d %I:%M:%S', time.localtime())
print time.strftime('%Y-%m-%d %H:%M:%S --%A--%c', time.localtime())
print time.strftime('%Y-%m-%d %H:%M:%S --%x--%X', time.localtime())
|
查看结果:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| [iyunv@www python]# python time1.py
1425623399.84
time.struct_time(tm_year=2015, tm_mon=3, tm_mday=6, tm_hour=14, tm_min=29, tm_sec=59, tm_wday=4, tm_yday=65, tm_isdst=0)
2015-03-06
15-03-06
2015-03-06 14:29:59
2015-03-06 02:29:59
2015-03-06 14:29:59 --Friday--Fri Mar 6 14:29:59 2015
2015-03-06 14:29:59 --03/06/15--14:29:59
datetime模块定义了下面这几个类:
datetime.date:表示日期的类。常用的属性有year, month, day;
datetime.time:表示时间的类。常用的属性有hour, minute, second, microsecond;
datetime.datetime:表示日期时间。
datetime.timedelta:表示时间间隔,即两个时间点之间的长度。
>>> from datetime import *
>>> print datetime.today()
2015-03-06 14:43:46.870936
>>> print datetime.now()
2015-03-06 14:43:51.313098
|
|
|