How long before or after the calculation date
datetime.str P Time ( 'Time DATE', "% Y-M-% D%% H:% M:% S") the string to date
.str F Time ( "% D%% Y-M-% H:% M:% S") the string into Date
# Use .strptime () the string to date: datetime.datetime.strptime ( 'Time DATE', "% Y-M-% D%% H:% M:% S") # Date of increase / decrease of n , n-month, n-day, n h, n-min, n-seconds # timedelta function, two time intervals. # The datetime.timedelta (Days = 0, = 0 weeks, hours = 0, = 0 minutes, 0 seconds The =, = 0 milliseconds, microseconds = 0)
Code
Import datetime C = datetime.datetime.strptime ( ' 1987-1-28 06:07:08 ' , " % Y-M-% D%% H:% M:% S " ) D = the datetime.timedelta (Days = . 1 ) Print ( ' original date: ' , C, End = ' \ T ' ) Print ( ' increased time: ' , D, End = ' \ T ' ) Print ( ' increase dates: ' , (C + D ) .strftime ( " % D%% Y-M-% H:% M:% S " )) DThe datetime.timedelta = (= weeks. 1 ) Print ( ' original date: ' , C, End = ' \ T ' ) Print ( ' increased time: ' , D, End = ' \ T ' ) Print ( ' after the date of the increase : ' , (C + D) .strftime ( " % D%% Y-M-% H:% M:% S " )) D = the datetime.timedelta (= 10 hours ) Print ( ' original date: ' , C , End = ' \ T ' ) Print ( 'Increase the time: ', D, End = ' \ T ' ) Print ( ' the increase date: ' , (C + D) .strftime ( " % D%% Y-M-% H:% M:% S " )) D = datetime .timedelta (= -10 minutes) # reduced 10 minutes Print ( ' original date: ' , C, End = ' \ T ' ) Print ( ' increased time: ' , D, End = ' \ T ' ) Print ( ' increased after the date: ' , (C + D) .strftime ( " % D%% Y-M-% H:% M:%S"))
result
Original Date: 1987-01-28 06:07:08 increasing time: 1 day, 0:00:00 increase later date: 1987-01-29 06:07:08 Original Date: 1987-01-28 06:07 : 08 increased time: 7 days, after 0:00:00 increase date: 1987-02-04 06:07:08 original date: 1987-01-28 06:07:08 increasing time: 10:00:00 after the increase date: 1987-01-28 16:07:08 original date: 1987-01-28 06:07:08 increasing time: -1 day, 23:50:00 increase dates: 1987-01-2805 : 57: 08