/** * Format a given date object to YYYY-MM-DD format. * * @param {Date} date The date object to be formatted. * @returns {string} The formatted date in YYYY-MM-DD format. */ function formatDateToYYYYMMDD(date) { const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0'); const formattedDate = `${year}-${month}-${day}`; return formattedDate; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter