JavaScript
  Home arrow JavaScript arrow Page 2 - Javascript Objects: More Date Methods
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Javascript Objects: More Date Methods
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-02-11

    Table of Contents:
  • Javascript Objects: More Date Methods
  • The GetHours() Method
  • Putting the Three Together
  • The GetTime() Method
  • The GetUTDate, Month, FullYear() Methods

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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

    More JavaScript Articles
    More By James Payne


       · I know, I know...another Date Object article?!? How many can there be? A lot. More...
     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT