Date: 2010may4
Language: javaScript
Level: beginner
Q. How do I display the current local time time?
A. Here are two ways:
function showTime() {
d, small_time, big_time;
d = new Date;
small_time = d.getHours() + ':' + zeroPad(d.getMinutes(), 2);
alert(small_time); // eg 14:04
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
| What this info useful to you? You can donate to say thanks |
Add a comment
Sign in to add a comment