# ! /Usr/bin/Python # Coding = UTF-8 From Datetime Import Datetime, timedelta """ Timedelta indicates the time difference between two datetime values. """ Now = Datetime. Now () past = Past = datetime (2010,11, 16 ) Timespan = Now- Past # This produces a negative number. Past- Nowattrs = [( " Days " , " Day " ),( ' Seconds ' , " Seconds " ),(' Microseconds ' , " Millisecond " ) # ('Min', "min"), ('max ', "Max "), ] For K, V In Attrs: " Timespan. % s = % s # % s " %(K, getattr (timespan, k), V) """ Total number of seconds of difference """ Timespan. total_seconds () """ To instantiate a timespan, pay attention to its Parameter order timedelta ([days [, seconds [, microseconds [, milliseconds [, minutes [, hours [, weeks]). """ Timespan = Timedelta (days = 1 ) Now -Timespan # The return value is of the datetime type. Now + Timespantimespan * 2# You can also take a ride. Represents 2x Timespan/13 # Add one month From Calendar Import Monthrangenow + Timedelta (days = monthrange (start. Year, start. month) [1])