Every line of 'mdn date' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
3 export default function formatDA(date, strFormat = 'MMM D, YYYY') { 4 if (!date) { 5 return; 6 } 7 8 try { 9 const parsedDateTime = parse(date, 'yyyyMMdd', new Date()); 10 const formattedDateTime = format(parsedDateTime, strFormat); 11 12 return formattedDateTime; 13 } catch (err) { 14 // swallow? 15 } 16 }
8 static formatDateYYYYMMDD(date) { 9 return DateFormatter.format(date, "yyyy-MM-dd"); 10 }
64 function dateToYYYYMMDD (date) { 65 if (date instanceof Date) { 66 return [ 67 date.getFullYear(), 68 String(date.getMonth() + 1).padStart(2, 0), 69 String(date.getDate()).padStart(2, 0), 70 ].join(""); 71 } 72 73 // TODO: better checking here? 74 75 return date; 76 }