v2.5.2
Giriş yap

Daha iyi bir yöntem var mı ?

mlhslckr
248 defa görüntülendi

Data baseden "2019-01-01T00:00:00" bu şekilde gelen veriyi JS kullanarak gg/aa/yyyy şeklinde yazmak istiyorum slice() metodunu mu kullanmayalım yoksa daha iyi bir yöntem var mı ?

{gelir.tarih.slice(8, 10)}-{gelir.tarih.slice(5, 7)}-{gelir.tarih.slice(0, 4)}

Çıktı:
15-02-2022

Bu şekilde.

istek61
436 gün önce

function oluşturup çok kolay kullanılabilir.

const today = new Date("2019-01-01T00:00:00");
const yyyy = today.getFullYear();
let mm = today.getMonth() + 1; 
let dd = today.getDate();

if (dd < 10) dd = '0' + dd;
if (mm < 10) mm = '0' + mm;

const formattedToday = dd + '/' + mm + '/' + yyyy;

console.log(formattedToday);