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類(lèi)中使用。
It uses an instance of the class and returns the total number of seconds covered in the given duration of that time instance.
它使用該類(lèi)的實(shí)例,并返回在該時(shí)間實(shí)例的給定持續(xù)時(shí)間內(nèi)覆蓋的總秒數(shù)。
Module:
模塊:
import datetimeClass:
類(lèi):
from datetime import timedeltaSyntax:
句法:
total_seconds()Parameter(s):
參數(shù):
None
沒(méi)有
Return value:
返回值:
The return type of this method is a number which is the total number of seconds covered in that period.
此方法的返回類(lèi)型是一個(gè)數(shù)字,該數(shù)字是該時(shí)間段內(nèi)覆蓋的總秒數(shù)。
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
總結(jié)
以上是生活随笔為你收集整理的Python timedelta total_seconds()方法与示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Java ObjectInputStre
- 下一篇: websocket python爬虫_p