This Python program retrieves and displays the current system date and time.
It uses the datetime module, which provides powerful tools for working with time and date values.
The output includes the date, time, and a formatted timestamp.
from datetime import datetime
# Get current date and time
now = datetime.now()
# Display output
print("--- Current Date and Time ---")
print("Date:", now.date())
print("Time:", now.time())
print("Formatted:", now.strftime("%Y-%m-%d %H:%M:%S"))
--- Current Date and Time ---
Date: 2025-09-28
Time: 13:18:00.123456
Formatted: 2025-09-28 13:18:00
- datetime.now() retrieves the current system timestamp
- .date() and .time() extract the date and time separately
- strftime() formats the output for readability
- You can customize the format string to match your preferred style