I have the following string in Python:
2023-07-03T14:30:00.000Z
How can I extract the hour and minute from this string in the most elegant way?
I have the following string in Python:
2023-07-03T14:30:00.000Z
How can I extract the hour and minute from this string in the most elegant way?
I think this way is the most elegant.
from dateutil.parser import parse
s = "2023-07-03T14:30:00.000Z"
dt = parse(s)
hour = dt.hour
minute = dt.minute
One way to do it is as follows:
from datetime import datetime
dts= "2023-07-03T14:30:00.000Z"
dto = datetime.strptime(dts[:-5], "%Y-%m-%dT%H:%M:%S")
hour = dto.hour
minute = dto.minute