Javascript Objects: More Date Methods - Putting the Three Together
(Page 3 of 5 )
You can put the hour, minutes, and seconds together of course (as well as the other units of time). Here is a quick program to demonstrate how to do so:
<html>
<body>
<script type="text/javascript">
var time = new Date()
document.write("The time is currently: ")
document.write(time.getHours())
document.write(":")
document.write(time.getMinutes())
document.write(":")
document.write(time.getSeconds())
</script>
</body>
</html>
This would result in the print out:
The time is currently: 18:23:08
Of course we could always get really anal and add milliseconds to that as well:
<html>
<body>
<script type="text/javascript">
var time = new Date()
document.write("The Present time is: ")
document.write(time.getHours())
document.write(".")
document.write(time.getMinutes())
document.write(".")
document.write(time.getSeconds())
document.write(".")
document.write(time.getMilliseconds())
</script>
</body>
</html>
And the fantastic result is:
The Present time is: 14.12.34.750
Next: The GetTime() Method >>
More JavaScript Articles
More By James Payne