python time

#!/usr/bin/env python
#coding:utf-8
import time

print time.time()
print time.mktime(time.localtime())
 
print time.gmtime()    #可加时间戳参数
print time.localtime() #可加时间戳参数
print time.strptime('2014-11-11', '%Y-%m-%d')
 
print time.strftime('%Y-%m-%d') #默认当前时间
print time.strftime('%Y-%m-%d',time.localtime()) #默认当前时间
print time.asctime()
print time.asctime(time.localtime())
print time.ctime(time.time())

'''
result:
1497515967.44
1497515967.0
time.struct_time(tm_year=2017, tm_mon=6, tm_mday=15, tm_hour=8, tm_min=39, tm_sec=27, tm_wday=3, tm_yday=166, tm_isdst=0)
time.struct_time(tm_year=2017, tm_mon=6, tm_mday=15, tm_hour=16, tm_min=39, tm_sec=27, tm_wday=3, tm_yday=166, tm_isdst=0)
time.struct_time(tm_year=2014, tm_mon=11, tm_mday=11, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=1, tm_yday=315, tm_isdst=-1)
2017-06-15
2017-06-15
Thu Jun 15 16:39:27 2017
Thu Jun 15 16:39:27 2017
Thu Jun 15 16:39:27 2017
[Finished in 0.2s]
'''
import datetime
'''
datetime.date:表示日期的类。常用的属性有year, month, day
datetime.time:表示时间的类。常用的属性有hour, minute, second, microsecond
datetime.datetime:表示日期时间
datetime.timedelta:表示时间间隔,即两个时间点之间的长度
timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]])
strftime("%Y-%m-%d")
'''
print datetime.datetime.now()
print datetime.datetime.now() - datetime.timedelta(seconds=5)

'''
result:
2017-06-15 16:42:31.309000
2017-06-15 16:42:26.309000
[Finished in 0.1s]
'''

 

posted @ 2017-06-15 16:43  AlamZ  阅读(157)  评论(0编辑  收藏  举报