If the hour is less than 10 hours the hours are usually placed in single digit form.
var currentHours = currentTime.getHours ( );   Is the following the only best way to get the hours to display as 09 instead of 9?
if (currentHours < 10)  currentHours = '0'+currentHours; 
                To change the getMinutes() method to 2 digit format:Use the getMinutes() method to get the minutes. Use the padStart() method to add a leading zero if it's necessary. The padStart method allows us to add a leading zero to the start of the string.
Your's method is good. Also take a note of it
var date = new Date(); currentHours = date.getHours(); currentHours = ("0" + currentHours).slice(-2); 
                        You can do this using below code,
create function,
function addZeroBefore(n) {   return (n < 10 ? '0' : '') + n; }   and then use it as below,
c = addZeroBefore(deg); 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With