xxxxxxxxxx
const date = new Date().toLocaleDateString()
console.log(date)
/*
Output : "5/17/2022"
*/
xxxxxxxxxx
var todayDate = new Date().toISOString()
console.log(todayDate);
xxxxxxxxxx
const dateString = "2020-10-30T12:52:27+05:30"; // ISO8601 compliant dateString
const D = new Date(dateString);
const result = D.getDate()+"/"+(D.getMonth()+1)+"/"+D.getFullYear();
//output: 30/10/2020
xxxxxxxxxx
Copied!
const date = new Date();
// ✅ DD/MM/YYYY
const result1 = new Date().toLocaleDateString('en-GB');
console.log(result1); // 👉️ 24/02/2023
xxxxxxxxxx
// Convert Date.now() to Formatted Date in "dd-MM-YYYY".
function convertDate(inputFormat) {
function pad(s) { return (s < 10) ? '0' + s : s; }
var d = new Date(inputFormat)
return [pad(d.getDate()), pad(d.getMonth()+1), d.getFullYear()].join('-')
}
console.log(convertDate('Mon Nov 19 13:29:40 2012')) // => "19-11-2012"
xxxxxxxxxx
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 = month+"/"+day+"/"+year;
alert(formattedDate); //03/02/2021
xxxxxxxxxx
var dateStr = 'dd/mm/yyyy';
var date = dateStr.split("/");
var dd=date[0];
var mm=date[1];
var yyyy=date[2];
dateObj = new Date(yyyy,mm,dd);
xxxxxxxxxx
var date_format = new Date();
document.write(innerHTML = date_format.getMonth()+'/'+ date_format.getDate()+'/'+date_format.getFullYear());
xxxxxxxxxx
const str = '22/04/2022';
const [day, month, year] = str.split('/');
console.log(day); // 22
console.log(month); // 04
console.log(year); // 2022
const date = new Date(+year, month - 1, +day);
console.log(date); // Fri Apr 22 2022
xxxxxxxxxx
var date_format = new Date();
document.write(innerHTML = date_format.getMonth()+'-'+ date_format.getDate()+'-'+date_format.getFullYear());