I am trying to convert the time(2018-08-03 11:30:00) in the datetime format(year, month, day, hour, min, sec) from a list in python. Can anyone help? Thank you so much for your time.
This is the preset code.
from datetime import datetime
class Meeting:
def __init__(self, start_time, end_time):
self.start_time = start_time
self.end_time = end_time
My code:
for meeting in meetings:
time1 = meeting.start_time
time2 = meeting.end_time
time3 = proposed_time
if time1 < time3 < time2:
return False
else:
return True
Here are the values that can be passed through my code.
meetings = [Meeting(datetime(2018, 8, 1, 9, 0, 0), datetime(2018, 8, 1, 11, 0, 0))
Here are some values that CANNOT work for my code. So, I would like to convert for my code.
meetings = [Meeting(2018-08-03 11:30:00, 2018-08-03 13:15:00), Meeting(2018-08-07 15:15:00, 2018-08-07 16:45:00)]
You can use the strptime
for conversion. datetime.strptime('2018-08-03 11:30:00', '%Y-%m-%d %I:%M:%S')
Finally, I was able to extract the time from the meetings list by making the time1, time2, and time3 as strings. Thanks for the inputs!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.