Untitled
unknown
plain_text
6 months ago
599 B
2
Indexable
import time from datetime import datetime def print_datetime_every_10_seconds(): while True: # Get the current date and time current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") # Print the current date and time print(f"Current Date and Time: {current_time}") # Sleep for 10 seconds time.sleep(10) # Trap Ctrl + C to stop the script try: print("Printing current date and time every 10 seconds. Press Ctrl+C to stop.") print_datetime_every_10_seconds() except KeyboardInterrupt: print("\nStopping script...")
Editor is loading...
Leave a Comment