🐍

Python YYYY-MM-DD

Utdata: 2025-01-15
Snabbreferens
Formatsträng
%Y-%m-%d
Utdata
2025-01-15

Formatera datum som YYYY-MM-DD i Python

🐍 Python
from datetime import datetime date = datetime.now() formatted = date.strftime('%Y-%m-%d') print(formatted) # Output: 2025-12-31

Tolka datumsträng

🐍 Python (Tolkning)
from datetime import datetime date_string = '2025-12-31' date = datetime.strptime(date_string, '%Y-%m-%d') print(date) # Output: 2025-12-31 00:00:00

Python datumformatkoder

Kod Betydelse Exempel
%d Day of month (01-31) 31
%m Month (01-12) 12
%Y Year with century 2025
%y Year without century (00-99) 25
%b Abbreviated month name Dec
%B Full month name December
%a Abbreviated weekday Wed
%A Full weekday name Wednesday

Andra format i Python

YYYY-MM-DD i andra språk

Officiell Dokumentation

För mer information om datumformatering i Python, se den officiella dokumentationen:

Python datumdokumentation →

Relaterade Sidor