Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function formatDateCustom(date, format) {
- const year = date.getFullYear().toString();
- const month = (date.getMonth() + 1).toString().padStart(2, '0');
- const day = date.getDate().toString().padStart(2, '0');
- return format
- .replace('YYY', year)
- .replace('MM', month)
- .replace('DD', day);
- }
- const inputDate = new Date('2023-08-11');
- const customFormat = 'YYYMMDD';
- const formattedDate = formatDateCustom(inputDate, customFormat);
- console.log(formattedDate); // Output: "20230811"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement