>>> import time>>> now_time = time.localtime()>>> now_timetime.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_year2014>>> for time in now_time:... print time... 201462821314751790
Past Time:
Import time # obtain the current time one day ago. strftime ('% Y-% m-% d % t', time. localtime (time. time ()-24*60*60) # obtain the current time 20 days ago. strftime ('% Y-% m-% d % t', time. localtime (time. time ()-20*24*60*60) # Take the first two hours of the current time 20 days ago. strftime ('% Y-% m-% d % t', time. localtime (time. time ()-20*24*60*60-2*60*60 ))
Future Time
Import time # obtain the current specific time after one day. strftime ('% Y-% m-% d % t', time. localtime (time. time () + 24*60*60) # obtain the current time of 20 days. strftime ('% Y-% m-% d % t', time. localtime (time. time () + 20*24*60*60) # Take the first two hours of the current time in 20 days. strftime ('% Y-% m-% d % t', time. localtime (time. time () + 20*24*60*60-2*60*60 ))
Past and future values of a certain unit of time
Import time # obtain the time of the last month. localtime () [1]-1 # Time of last year. localtime () [0]-1 # obtain the month time after two months. localtime () [1] + 2