Чтобы уменьшить количество часов в модуле Python datetime, вы можете использовать несколько методов. Вот несколько вариантов:
Метод 1: использование timedelta
from datetime import datetime, timedelta
# Get the current datetime
current_datetime = datetime.now()
# Decrease hours by a specific value
decreased_datetime = current_datetime - timedelta(hours=3)
# Print the decreased datetime
print(decreased_datetime)
Метод 2: использование replace
from datetime import datetime
# Get the current datetime
current_datetime = datetime.now()
# Decrease hours by a specific value
decreased_datetime = current_datetime.replace(hour=current_datetime.hour - 3)
# Print the decreased datetime
print(decreased_datetime)
Метод 3. Использование арифметических операций
from datetime import datetime, timedelta
# Get the current datetime
current_datetime = datetime.now()
# Decrease hours by a specific value
decreased_datetime = current_datetime - timedelta(hours=3)
# Print the decreased datetime
print(decreased_datetime)