'datetime.timedelta' object has no attribute 'minute'
时间: 2023-07-14 13:58:31 浏览: 322
c#中DateTime.Now函数的使用详解
5星 · 资源好评率100%
`datetime.timedelta` object does not have a direct attribute called `minute`. However, you can access the minutes component of a `timedelta` object using the `total_seconds()` method. Here's an example:
```python
import datetime
delta = datetime.timedelta(hours=1, minutes=30)
total_minutes = delta.total_seconds() // 60
minutes = total_minutes % 60
print(minutes) # Output: 30
```
In the above code, we create a `timedelta` object representing an hour and a half. Then, we use the `total_seconds()` method to get the total number of seconds in the `timedelta` object. We divide it by 60 to get the total number of minutes and use the modulo operator `%` to extract the remaining minutes after removing the hours.
阅读全文