Date and Time Formatting
Date and Time Formatting is a reusable Python snippet. Format, parse, and manipulate dates and times using the datetime module. The full implementation: from datetime import datetime, date, time, timedelta # Current time now = datetime.now() today = date.today() # Formatting now.strftime("%Y-%m-%d %H:%M:%S") # "2026-06-06 14:30:00" now.strftime("%A, %B %d, %Y") # "Saturday, June 06, 2026" # Parse strings dt = datetime.strptime("2024-01-15", "%Y-%m-%d") # Date arithmetic yesterday = today - timedelta(days=1) next_week = today + timedelta(weeks=1) diff = next_week - yesterday # Timezone aware (Python 3.9+) from zoneinfo import ZoneInfo ny = datetime.now(ZoneInfo("America/New_York")) london = datetime.now(ZoneInfo("Europe/London")) It belongs to the Datetime Module area of the standard library. This snippet uses only the Python standard library with no third-party dependencies, so it runs on any modern Python 3 interpreter. Browse more patterns in the snippet library, or paste the code straight into the playground to experiment with it.