#Time module datetime import datetime #Get the current time cuttent_time=datetime.datetime.now() print (cuttent_time) #Get only the year, month and day cuttent_day=datetime.date.today() print (cuttent_day) #Get tomorrow's date tomorrow=datetime.date.today()+datetime.timedelta( days = 1 ) print (tomorrow) #Get the hours after tomorrow tomorrow=datetime.datetime.today()+datetime.timedelta( days = 1 , hours = 2 ) print (tomorrow) #Get the hours before yesterday yesterday=datetime.datetime.today()-datetime.timedelta( days = 1 , hours = 3 ) print (yesterday) #Custom time cus_time=datetime.datetime( 2018 , 5 , 20 , 12 , 24 , 30 ) #The time difference from the current time time_diff=cus_time-datetime.datetime.now() print (time_diff) #Difference days days=time_diff.days print (days) #Difference seconds seconds=time_diff.total_seconds() print (seconds) #Formatted operation cus_time2=datetime.datetime( 2018 , 6 , 20 , 23 , 12 , 23 ) format_str=cus_time2.strftime("%Y/%m/%d %I/%M/%S") print(format_str) #逆向 time_cus=datetime.datetime.strptime(format_str,"%Y/%m/%d %I/%M/%S") print(time_cus) #Convert the time of datetime into a time tuple tuple_time=cus_time2.timetuple() print (tuple_time)
time module datetime
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324722629&siteId=291194637
Ranking