Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
194
rated 0 times [  196] [ 2]  / answers: 1 / hits: 83334  / 11 Years ago, thu, september 19, 2013, 12:00:00

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;

More From » javascript

 Answers
43

Your's method is good. Also take a note of it



var date = new Date();
currentHours = date.getHours();
currentHours = (0 + currentHours).slice(-2);

[#75600] Wednesday, September 18, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
luna

Total Points: 698
Total Questions: 114
Total Answers: 93

Location: Israel
Member since Wed, Apr 14, 2021
3 Years ago
luna questions
;