Programming Tips - javaScript: display the current local time

Date: 2010may4 Language: javaScript Platform: web Level: beginner Q. javaScript: display the current local time A. Here are two ways:
function showTime() { const d = new Date(); const small_time = d.getHours() + ':' + zeroPad(d.getMinutes(), 2); alert(small_time); // eg 14:04 const big_time = d.toLocaleTimeString(); alert(big_time); // eg 2:04:05 PM }
The helper function zeroPad() can be found here: http://davekb.com/search.php?target=javascript+zeroPad