datetime.datetime.strftime()
datetime.datetime.strftime() is a Python method in the Datetime Module category. Formats a datetime object as a string according to a format code. The syntax is datetime.datetime.strftime(format). Parameters: format — strftime format string. Returns: Formatted string. A typical example: dt = datetime.now()
dt.strftime("%Y-%m-%d %H:%M") # "2026-06-06 14:30". A close sibling is datetime.date(), which creates a date object representing a specific date (year, month, day). A close sibling is datetime.date.today(), which returns the current local date. A close sibling is datetime.datetime.now(), which returns the current local date and time with optional timezone. A close sibling is datetime.datetime.utcnow(), which returns the current UTC date and time (deprecated, use now(timezone.utc)). More about this category: Date and time handling — date, datetime, timedelta, timezone. For a broader walkthrough, read the Datetime Module guide. Related Datetime Module entries: datetime.date(), datetime.date.today(), datetime.datetime.now(), datetime.datetime.utcnow(), datetime.datetime.fromtimestamp(), datetime.datetime.strptime().