How can I convert time and date with zero prefix by javascript ?

Ask a question+

Hello developer,
I have a time like 1:2:5 1/2/2020 and I want to convert it to 01:02:05 01/02/2020
How can I do it by javascript?

add comment

1 Answer


Yes, you can do it by the following javascript code:

const hour = 1;
const fullHour = `0${hour}`.slice(-2); //fullHour = ‘01’
And then do it for the rest of datetime

add comment

Your Answer