Write a Python program to get the current time


The Python code prints the current time using the datetime module. Here's how the code works:

  • datetime module is imported.
  • datetime.datetime.now() function is called to get the current date and time.
  • time() function is called on the datetime object to extract the time.
  • print() function is used to output the time to the console.

So, the output of the program is the current time in hours, minutes, seconds, and microseconds.

Source Code

import datetime
print(datetime.datetime.now().time())

Output

15:24:50.977802

Example Programs