I
I
Ilya2021-12-10 17:14:14
Python
Ilya, 2021-12-10 17:14:14

How to change the time format in Python?

Hello, I have the code -

currect_datetime = datetime.now()
currect_time = f'{currect_datetime.hour}:{currect_datetime.minute}'


my task is to compare the time with the current one and the given one, but when the clock is
16:09 or less than 09, then the output in currect_time will be 16:9 , and I need this format:
16:09
How could I do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2021-12-10
@stead

Don't be fooled:
currect_datetime.strftime('%H:%M')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question