const date = new Date(); const formattedDate = date.toISOString().slice(0, 19).replace('T', ' '); console.log(formattedDate); // Output: 2023-05-07 06:22:28// yyyy-mm-dd new Date().toISOString().slice(0, 10)let today = new Date() today.toISOString().split('T')[0]// `date` is a `Date` object const formatYmd = date => date.toISOString().slice(0, 10); // Example formatYmd(new Date()); // 2020-05-06const yourDate = new Date() yourDate.toISOString().split('T')[0]date.value.split("-").reverse().join("-"); //"2021-01-17" --> 17-01-2021function convert(str) { var date = new Date(str), mnth = ("0" + (date.getMonth() + 1)).slice(-2), day = ("0" + date.getDate()).slice(-2); return [date.getFullYear(), mnth, day].join("-"); } console.log(convert("Thu Jun 09 2011 00:00:00 GMT+0530 (India Standard Time)")) //-> "2011-06-08"function getDateString(datetime){ let d = datetime.getDate(); let m = datetime.getMonth(); return `${datetime.getFullYear()}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d}`; }function formatDate(date) { const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0'); const hours = String(date.getHours()).padStart(2, '0'); const minutes = String(date.getMinutes()).padStart(2, '0'); const seconds = String(date.getSeconds()).padStart(2, '0'); return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; } // Get the current date and time const currentDate = new Date(); // Format the date using the defined function const formattedDate = formatDate(currentDate); console.log(formattedDate); // Example output: "2022-01-31 09:15:30"var d = new Date, dformat = [(d.getMonth()+1).padLeft(), d.getDate().padLeft(), d.getFullYear()].join('/') +' ' + [d.getHours().padLeft(), d.getMinutes().padLeft(), d.getSeconds().padLeft()].join(':'); //=> dformat => '05/17/2012 10:52:21'2021-08-25T04:11:23.576