w3resource

Python: System time print Python

Python Basic: Exercise-98 with Solution

Write a Python program to get system time.

Note : The system time is important for debugging, network information, random number seeds, or something as simple as program performance.

Pictorial Presentation:

Get the system time

Sample Solution-1:

Python Code:

# Import the 'time' module to work with time-related functions.
import time

# Print an empty line for formatting.
print()

# Get and print the current time using 'time.ctime()'.
print(time.ctime())

# Print an empty line for formatting.
print()

Sample Output:

Thu Apr 20 18:25:06 2017

Sample Solution-2:

Python Code:

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

Sample Output:

2021-06-04 08:40:11.391443

Python Code Editor:

 

Previous: Write a Python program to list the special variables used within the language.
Next: Write a Python program to clear the screen or terminal.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.