$0.15

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

Ask a question+
0

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?
Thanks!

vucms 0
add comment

1 Answer

0

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

vucms 0
add comment

Your Answer