0

I have a string in the str format

 PATTERN_OUT = "%H:%M"
date_time = (datetime.strftime(enddateandtime, PATTERN_OUT))

I need to convert it to datetime.time. How can this be done?

Иван
  • 15
  • 4

1 Answers1

2

You can utilize the fact that time string is \d\d:\d\d. Look at the following snippet.

from datetime import time
time_str = "10:01"
time(*map(int, time_str.split(':')))

Add exception handler if required.