Part of the series

Several example codes

~1 min read • Updated Sep 28, 2025

Program Overview

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.


Python Code:


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"))

Sample Output:


--- Current Date and Time ---  
Date: 2025-09-28  
Time: 13:18:00.123456  
Formatted: 2025-09-28 13:18:00

Explanation:

- 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


Written & researched by Dr. Shahin Siami