Get today's countdown (remaining seconds) using python

An activity will be over today, and I want to show users the countdown so they can hurry up.

Python Code

from datetime import datetime
from datetime import time as dt_time
from datetime import timedelta


def get_today_countdown() -> int:
    now = datetime.now()
    # zero o'clock in tomorrow's morning
    next_day = datetime.combine(now + timedelta(days=1), dt_time.min)
    return int((next_day - now).total_seconds())


# test
print(f'The remaining seconds today: {get_today_countdown()}')
print(f'The remaining hours today: {get_today_countdown() / 3600:.2f}')

Output example:

The remaining seconds today: 13461
The remaining hours today: 3.74
Posted on 2022-06-17