标签:python
>>> import time >>> now_time = time.localtime() >>> now_time time.struct_time(tm_year=2014, tm_mon=6, tm_mday=28, tm_hour=21, tm_min=31, tm_sec=47, tm_wday=5, tm_yday=179, tm_isdst=0) >>> type(now_time) <type 'time.struct_time'> >>> the_year = now_time[0] >>> the_year 2014 >>> for time in now_time: ... print time ... 2014 6 28 21 31 47 5 179 0
import time #取一天前的当前具体时间 time.strftime('%Y-%m-%d %T',time.localtime(time.time()-24*60*60)) #取20天前的当前具体时间 time.strftime('%Y-%m-%d %T',time.localtime(time.time()-20*24*60*60)) #取20天前当前具体时间的前2小时 time.strftime('%Y-%m-%d %T',time.localtime(time.time()-20*24*60*60-2*60*60))
import time #取一天后的当前具体时间 time.strftime('%Y-%m-%d %T',time.localtime(time.time()+24*60*60)) #取20天后的当前具体时间 time.strftime('%Y-%m-%d %T',time.localtime(time.time()+20*24*60*60)) #取20天后当前具体时间的前2小时 time.strftime('%Y-%m-%d %T',time.localtime(time.time()+20*24*60*60-2*60*60))
import time #取上一月月份 time.localtime()[1]-1 #取去年年份 time.localtime()[0]-1 #取两个月后的月份 time.localtime()[1]+2
标签:python
原文地址:http://blog.csdn.net/qiwsir/article/details/35601687