Muunna DD/MM/YYYY MM/YYYY-muotoon
15/01/2025 → 01/2025
Pikamuunnin
→
01/2025
Miten Muunnetaan DD/MM/YYYY MM/YYYY-muotoon
Muuntaminen DD/MM/YYYY-muodosta MM/YYYY-muotoon sisältää päivämääräkomponenttien uudelleenjärjestelyn:
Muodosta
DD/MM/YYYY
15/01/2025
muotoon
MM/YYYY
01/2025
1
Tunnista Osat
DD/MM/YYYY-muodossa: Day-Month-Year format commonly used in Europe, Asia, and most of the world
2
Järjestä Uudelleen
Järjestä uudelleen vastaamaan MM/YYYY-muotoa: Month-year format commonly used for credit cards, expiration dates, and monthly reports
3
Säädä Erotin
Vaihda erotin "/" muotoon "/" tarvittaessa.
Koodiesimerkit
JavaScript
// Muunna DD/MM/YYYY MM/YYYY-muotoon
function convertDate(dateStr) {
// Jäsennä DD/MM/YYYY
const parts = dateStr.split('/');
const [day, month, year] = parts;
// Muotoile MM/YYYY-muodossa
return `${year}-${month}-${day}`;
}
console.log(convertDate('15/01/2025')); // 01/2025
Python
from datetime import datetime
# Muunna DD/MM/YYYY MM/YYYY-muotoon
date_str = '15/01/2025'
date = datetime.strptime(date_str, '%d/%m/%Y')
result = date.strftime('%Y-%m-%d')
print(result) # 01/2025