Chuyển đổi YYYY-MM-DD sang DD/MM/YYYY
2025-01-15 → 15/01/2025
Chuyển Đổi Nhanh
→
15/01/2025
Cách Chuyển Đổi YYYY-MM-DD sang DD/MM/YYYY
Chuyển đổi từ YYYY-MM-DD sang DD/MM/YYYY cần sắp xếp lại các thành phần ngày:
Từ
YYYY-MM-DD
2025-01-15
sang
DD/MM/YYYY
15/01/2025
1
Xác Định Các Phần
Trong YYYY-MM-DD: ISO 8601 standard format, ideal for sorting and international use
2
Sắp Xếp Lại
Sắp xếp lại để khớp với định dạng DD/MM/YYYY: Day-Month-Year format commonly used in Europe, Asia, and most of the world
3
Điều Chỉnh Dấu Phân Cách
Thay đổi dấu phân cách từ "-" sang "/" nếu cần.
Ví Dụ Code
JavaScript
// Chuyển đổi YYYY-MM-DD sang DD/MM/YYYY
function convertDate(dateStr) {
// Phân tích YYYY-MM-DD
const parts = dateStr.split('-');
const [year, month, day] = parts;
// Định dạng thành DD/MM/YYYY
return `${day}/${month}/${year}`;
}
console.log(convertDate('2025-01-15')); // 15/01/2025
Python
from datetime import datetime
# Chuyển đổi YYYY-MM-DD sang DD/MM/YYYY
date_str = '2025-01-15'
date = datetime.strptime(date_str, '%Y-%m-%d')
result = date.strftime('%d/%m/%Y')
print(result) # 15/01/2025