日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

Python timedelta total_seconds()方法与示例

發(fā)布時(shí)間:2025/3/11 python 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python timedelta total_seconds()方法与示例 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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 datetime

Class:

類(lèi):

from datetime import timedelta

Syntax:

句法:

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)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。