'datetime.timedelta' object has no attribute 'minute'
时间: 2023-07-14 19:58:31 浏览: 353
`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.
阅读全文