Python timedelta total_seconds()方法与示例
Python timedelta.total_seconds()方法 (Python timedelta.total_seconds() Method)
timedelta.timedeltotal_seconds() method is used in the timedelta class of module datetime.
timedelta.timedeltotal_seconds()方法在模塊datetime的timedelta類中使用。
It uses an instance of the class and returns the total number of seconds covered in the given duration of that time instance.
它使用該類的實例,并返回在該時間實例的給定持續時間內覆蓋的總秒數。
Module:
模塊:
import datetimeClass:
類:
from datetime import timedeltaSyntax:
句法:
total_seconds()Parameter(s):
參數:
None
沒有
Return value:
返回值:
The return type of this method is a number which is the total number of seconds covered in that period.
此方法的返回類型是一個數字,該數字是該時間段內覆蓋的總秒數。
Example:
例:
## Python program to illustrate ## the use of total_seconds function from datetime import time, timedelta ## total_seconds function x = timedelta(minutes = 2*15) total = x.total_seconds() print("Total seconds in 30 minutes:", total) print()## time can be negative also x = timedelta(minutes = -2*15) total = x.total_seconds() print("Total seconds:", total) print()x = timedelta(days = 1, minutes = 50, seconds = 56) total = x.total_seconds() print("Total seconds in the given duration:", total) print()x = timedelta(hours=1,minutes= 50,seconds= 40) y = timedelta(hours=10,minutes= 20,seconds= 39) d = y-x print("Total seconds covered in subtracting:", d.total_seconds()) print()x = timedelta(hours=1,minutes= 50,seconds= 40) y = timedelta(hours=10,minutes= 20,seconds= 39) d = y+x print("Total seconds covered in adding:", d.total_seconds()) print()x = timedelta(hours=1,minutes= 50,seconds= 40) y = timedelta(hours=10,minutes= 20,seconds= 39) d = y%x print("Total seconds remaining when y is divided by x", d.total_seconds()) print()Output
輸出量
Total seconds in 30 minutes: 1800.0Total seconds: -1800.0Total seconds in the given duration: 89456.0Total seconds covered in subtracting: 30599.0Total seconds covered in adding: 43879.0Total seconds remaining when y is divided by x 4039.0翻譯自: https://www.includehelp.com/python/timedelta-total_seconds-method-with-example.aspx
總結
以上是生活随笔為你收集整理的Python timedelta total_seconds()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java ObjectInputStre
- 下一篇: python 线程模块_Python线程