Преобразование в строку

Простые типы / Дата и время

from datetime import datetime

# Фиксированный момент: вывод не меняется
moment = datetime(2027, 1, 1, 22, 13, 20)

# %I - 12-часовой формат, %p - AM/PM
short_style = moment.strftime("%m/%d/%y %I:%M %p")
# short_style is '01/01/27 10:13 PM'

custom_style = moment.strftime("%Y-%m-%d")
# custom_style is '2027-01-01'

# Без формата: дата, пробел, время
standard_style = str(moment)
# standard_style is '2027-01-01 22:13:20'

# ISO 8601: "T" между датой и временем
iso_style = moment.isoformat()
# iso_style is '2027-01-01T22:13:20'

# f-строка принимает те же коды
str_format = f"Today {moment:%d %B}"
# str_format is 'Today 01 January'

print(f"{short_style = }")
print(f"{custom_style = }")
print(f"{standard_style = }")
print(f"{iso_style = }")
print(f"{str_format = }")