Home arrow JavaScript arrow Page 2 - Javascript Objects: More Date Methods
JAVASCRIPT

Javascript Objects: More Date Methods


We previously left off discussing a smattering of JavaScript Date Objects. In this tutorial we will continue the discussion, picking up with the GetFullYear() Method. There are a ton of Date methods, so let's get started.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
February 11, 2008
TABLE OF CONTENTS:
  1. · Javascript Objects: More Date Methods
  2. · The GetHours() Method
  3. · Putting the Three Together
  4. · The GetTime() Method
  5. · The GetUTDate, Month, FullYear() Methods

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Javascript Objects: More Date Methods - The GetHours() Method
(Page 2 of 5 )

This method returns the hour as a two digit number (unless of course the time is less than ten, in which case it is a one digit number, duh).


<html>

<body>

<script type="text/javascript">

var hours = new Date()

document.write(hours.getHours())

</script>

</body>

</html>

This program creates a variable named hours and stores the current hour based on your system time in it. It then writes it to the screen, like so:

  16

If we wanted to extract the hour from a specified date within a variable, we could do that as well:


<html>

<body>

<script type="text/javascript">

var fluxcapacitor = new Date("April 22, 1977 10:30:00")

document.write(fluxcapacitor.getHours())

</script>

</body>

</html>

This sample creates a variable named fluxcapacitor and stores the value April 22, 1977 10:30:00 in it (the time the great James Payne entered the world muahaha). It then retrieves the hour from the variable and writes it to the screen, resulting in:

  10

The GetMinutes() Method

This works like the GetHours() method, only with minutes.


<html>

<body>

<script type="text/javascript">

var minutes = new Date()

document.write(minutes.getMinutes())

</script>

</body>

</html>

The result: 22

The GetSeconds() Method

Again, the code is the same except it is for seconds:

<html>

<body>

<script type="text/javascript">

var seconds = new Date()

document.write(seconds.getSeconds())

</script>

</body>

</html>

The result is:

  28


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials