$0.4

how to write a function to get the current date?

Ask a question+
2

Note: Pass a separator as an argument.
Test Data :

console.log(curday('/'));   // "11/13/2014" 
console.log(curday('-'));   // "11-13-2014"
add comment

1 Answer

1
const curday = (sp) => {
    today = new Date();
    let dd = today.getDate();
    let mm = today.getMonth()+1;
    let yyyy = today.getFullYear();

    if(dd<10) dd='0'+dd;
    if(mm<10) mm='0'+mm;
    return (mm+sp+dd+sp+yyyy);
};
console.log(curday('/'));
console.log(curday('-'));
Marc Gravell 520
add comment

Your Answer