🐍
Python DD/MM/YYYY
輸出: 15/01/2025
快速參考
格式字串
%d/%m/%Y
輸出
15/01/2025
在Python中將日期格式化為DD/MM/YYYY
🐍 Python
from datetime import datetime
date = datetime.now()
formatted = date.strftime('%d/%m/%Y')
print(formatted) # Output: 31/12/2025解析日期字串
🐍 Python (解析)
from datetime import datetime
date_string = '31/12/2025'
date = datetime.strptime(date_string, '%d/%m/%Y')
print(date) # Output: 2025-12-31 00:00:00Python日期格式代碼
| 代碼 | 含義 | 範例 |
|---|---|---|
| %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 |
Python的其他格式
其他語言的DD/MM/YYYY
官方文檔
有關Python日期格式的更多資訊,請參閱官方文檔: