JavaScript Zdobądź bieżącą datę JYYY-MM-DD
var todayDate = new Date().toISOString().slice(0, 10);
console.log(todayDate);
Run code snippet
Code Alchemy
var todayDate = new Date().toISOString().slice(0, 10);
console.log(todayDate);
Run code snippet
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
today = mm + '/' + dd + '/' + yyyy;
document.write(today);
const yourDate = new Date()
yourDate.toISOString().split('T')[0]
const date = new Date().toLocaleDateString()
console.log(date)
// Output
// 5/23/2022 -> mm/dd/yyyy
const dateArray = date.split("/")
const dateArray.map(d => d.length == 1 && d.length != 4 ? "0"+d : d)
const formatedDate = `${day}.${dateArray[0]}.${dateArray[2]}`
console.log(formatedDate)
// Output
// 23.05.2022 -> dd.mm.yyyy
date.value.split("-").reverse().join("-"); //"2021-01-17" --> 17-01-2021
function pad2(n) {
return (n < 10 ? '0' : '') + n;
}
var date = new Date();
var month = pad2(date.getMonth()+1);//months (0-11)
var day = pad2(date.getDate());//day (1-31)
var year= date.getFullYear();
var formattedDate = day+"-"+month+"-"+year;
alert(formattedDate); //28-02-2021