1

I need to get the current date and time upon running the program, both as their respective objects in the datetime library. I have been able to get a date object for the current date fine:

datetime.date.today()

but how can i get a time object for the current time? datetime.time.now() doesn't work, and datetime.time() is used to instantiate a time object by passing in your own values, but i want to just get a time object with the current time information.

carbaretta
  • 303
  • 1
  • 6
  • 1
    Does this answer your question? [Extract time from datetime and determine if time (not date) falls within range?](https://stackoverflow.com/questions/16138744/extract-time-from-datetime-and-determine-if-time-not-date-falls-within-range) – azro Aug 23 '20 at 17:39

1 Answers1

0
>>> import datetime
>>> n = datetime.datetime.now()
>>> n
datetime.datetime(2020, 8, 23, 12, 37, 51, 595180)
>>> n.date()
datetime.date(2020, 8, 23)
>>> n.time()
datetime.time(12, 37, 51, 595180)
Tim Peters
  • 67,464
  • 13
  • 126
  • 132