Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Javascript convert from string number to integer

I am creating an excel date format while I using JavaScript but I got stuck about convert string to integer.

function getCurrentDateFormat (date,errorValue, removeSecond, clientTimeZoneOffset) {

    if (date !== undefined && date !== null) {
        const currDate = new Date(date)

        const currDay = currDate.getDate()
        const currMonth = currDate.getMonth()
        const currYear = currDate.getFullYear()
        const currHour = currDate.getHours().toString().padStart(2,0)
        const currMinutes = currDate.getMinutes()
        const currSeconds = currDate.getSeconds()

        return currDay + "/" + currMonth + 1 + "/" + currYear + " " + currHour + ":" + currMinutes + ":" + currSeconds
 
    }
    else {
        return errorValue
    }

}

This function give me this result : 30/01/2024 9:27:24

I want to make hour like 09. When I try to make integer zero(0) disappear. How can fix this situation?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try the following

var s = "0" + currHour;
var hr= s.substr(s.length-2);

return currDay + "/" + currMonth + 1 + "/" + currYear + " " + hr + ":" + 
currMinutes + ":" + currSeconds;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading