將MM/YYYY轉換為DD/MM/YYYY
01/2025 → 15/01/2025
快速轉換器
→
15/01/2025
如何將MM/YYYY轉換為DD/MM/YYYY
從MM/YYYY轉換到DD/MM/YYYY需要重新排列日期組成部分:
從
MM/YYYY
01/2025
到
DD/MM/YYYY
15/01/2025
1
識別各部分
在MM/YYYY中: Month-year format commonly used for credit cards, expiration dates, and monthly reports
2
重新排列
重新排序以匹配DD/MM/YYYY格式: Day-Month-Year format commonly used in Europe, Asia, and most of the world
3
調整分隔符
如有需要,將分隔符從"/"更改為"/"。
程式碼範例
JavaScript
// 將MM/YYYY轉換為DD/MM/YYYY
function convertDate(dateStr) {
// 解析MM/YYYY
const parts = dateStr.split('/');
const [year, month, day] = parts;
// 格式化為DD/MM/YYYY
return `${day}/${month}/${year}`;
}
console.log(convertDate('01/2025')); // 15/01/2025
Python
from datetime import datetime
# 將MM/YYYY轉換為DD/MM/YYYY
date_str = '01/2025'
date = datetime.strptime(date_str, '%Y-%m-%d')
result = date.strftime('%d/%m/%Y')
print(result) # 15/01/2025