How to get datetime.date and datetime.time from time.ctime () in python?

I am trying to access to time.ctime()do some simple logical operations. I found this procedure :

datetime.datetime.strptime(time.ctime(), "%a %b %d %H:%M:%S %Y")

What gives me this:

datetime.datetime(2017, 10, 5, 17, 7, 51)

How can I access the time.ctime()date and time separately so that I can get:

datetime.date(2017, 10, 5)

and

datetime.time(17, 7)
+4
source share
1 answer

You can use date()and time()to retrieve them:

dt = datetime.datetime(2017, 10, 5, 17, 7, 51)
d = dt.date()
t = dt.time()
+2
source

Source: https://habr.com/ru/post/1686989/


All Articles