Вы можете просто использовать функции datetime.date()
и datetime.time()
:
import datetime
date = datetime.datetime.strptime('17/12/2018', '%d/%m/%Y') # this is a datetime
time = datetime.datetime.strptime('13:26:09', '%H:%M:%S') # this is also a datetime
print(date.date()) # just the date
print(time.time()) # just the time
Вывод:
2018-12-17 # do date.strftime('%%d/%m/%Y') to create the string representation you want
13:26:09 # default visualisation is same as you want
Вы создаете 2 экземпляра даты-времени - один только с указанием времени,другая покупка только с указанием даты.Другой параметр предоставляется по умолчанию.
Альтернативно вы можете использовать:
date = datetime.datetime.strptime('17/12/2018', '%d/%m/%Y').date() # date object
time = datetime.datetime.strptime('13:26:09', '%H:%M:%S').time() # time object