![]() Similar to the previous example, we will get the difference, set our time units, and calculate the amounts corresponding to each time unit.ĭatetime_1 = datetime. This example explains how to get the time difference in weeks and days using the same dates as in Example 1. # Time difference between dates: 3513 hours, 51 minutes and 9 seconds Print("Time difference: %d hours, %d minutes and %d seconds" Seconds = minutes # Divide remainder to find seconds Minutes = divmod(hours, minute) # Divide remainder to find minutes ![]() Hours = divmod(diff.total_seconds(), hour) # Calculate the amount of full hours % (hours, minutes, seconds ) ) # Time difference between dates: 3513 hours, 51 minutes and 9 seconds Seconds = minutes # Divide remainder to find seconds print ( "Time difference: %d hours, %d minutes and %d seconds" Minutes = divmod (hours, minute ) # Divide remainder to find minutes total_seconds ( ), hour ) # Calculate the amount of full hours If you still have doubts about the timedelta object fields, you can use the following line to ease your mind (of course this is only true if there are microsecond differences between datetimes). of Microseconds:", diff.microseconds) # Number of microseconds in the remainder of Seconds:", conds) # Number of seconds in the remainder of Days:", diff.days) # Number of days between the datetimes of Total Seconds:", diff.total_seconds()) # Total difference in seconds microseconds ) # Number of microseconds in the remainder # of Total Seconds: 12649869.0 # of Days: 146 # of Seconds: 35469 # of Microseconds: 0 ![]() seconds ) # Number of seconds in the remainder print ( "No. ![]() days ) # Number of days between the datetimes print ( "No. total_seconds ( ) ) # Total difference in seconds print ( "No. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |