JavaScript
  Home arrow JavaScript arrow 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  
Dedicated Servers  
Download TestComplete 
IBM® developerWorks 
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
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Javascript Objects: More Date Methods
    (Page 1 of 5 )

    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.

     

    Method

    What it Does

    Date()

    Used to retrieve today's date and time

    getDate()

    Used to retrieve the day of the month from a Date object (from 1-31)

    getDay()

    Used to retrieve the day of the week from a Date object (from 0-6)

    getMonth()

    Used to retrieve the month from a Date object (from 0-11)

    getFullYear()

    Used to retrieve the year, as a four-digit number, from a Date object

    getYear()

    Used to retrieve the year, as a two-digit or a four-digit number, from a Date object.

    getHours()

    Used to retrieve the hour of a Date object (from 0-23)

    getMinutes()

    Used to retrieve the minutes of a Date object (from 0-59)

    getSeconds()

    Used to retrieve the seconds of a Date object (from 0-59)

    getMilliseconds()

    Used to retrieve the milliseconds of a Date object (from 0-999)

    getTime()

    Used to retrieve the number of milliseconds since midnight Jan 1, 1970

    getTimezoneOffset()

    Gets the difference in minutes between local time and Greenwich Mean Time (GMT)

    getUTCDate()

    Used to retrieve the day of the month from a Date object according to universal time (from 1-31)

    getUTCDay()

    Used to retrieve the day of the week from a Date object according to universal time (from 0-6)

    getUTCMonth()

    Used to retrieve the month from a Date object according to universal time (from 0-11)

    getUTCFullYear()

    Used to retrieve the four-digit year from a Date object according to universal time

    getUTCHours()

    Used to retrieve the hour of a Date object according to universal time (from 0-23)

    getUTCMinutes()

    Used to retrieve the minutes of a Date object according to universal time (from 0-59)

    getUTCSeconds()

    Used to retrieve the seconds of a Date object according to universal time (from 0-59)

    getUTCMilliseconds()

    Used to retrieve the milliseconds of a Date object according to universal time (from 0-999)

    parse()

    Uses a date string to return the number of milliseconds from midnight of January 1, 1970

    setDate()

    Used to set the day of the month in a Date object (from 1-31)

    setMonth()

    Used to set the month in a Date object (from 0-11)

    setFullYear()

    Used to set the year in a Date object (four digits)

    setYear()

    Used to set the year in the Date object (two or four digits)

    setHours()

    Used to set the hour in a Date object (from 0-23)

    setMinutes()

    Used to set the minutes in a Date object (from 0-59)

    setSeconds()

    Used to set the seconds in a Date object (from 0-59)

    setMilliseconds()

    Used to set the milliseconds in a Date object (from 0-999)

    setTime()

    Used to calculate a date and time by adding/subtracting a certain number of milliseconds to or from midnight January 1, 1970

    setUTCDate()

    Used to set the day of the month in a Date object according to universal time (from 1-31)

    setUTCMonth()

    Used to set the month in a Date object according to universal time (from 0-11)

    setUTCFullYear()

    Used to set the year in a Date object according to universal time (a four digit value)

    setUTCHours()

    Used to set the hour in a Date object according to universal time (from 0-23)

    setUTCMinutes()

    Used to set the minutes in a Date object according to universal time (from 0-59)

    setUTCSeconds()

    Used to set the seconds in a Date object according to universal time (from 0-59)

    setUTCMilliseconds()

    Used to set the milliseconds in a Date object according to universal time (from 0-999)

    toSource()

    Returns the source code of an object

    toString()

    Used to convert a Date object to a string

    toGMTString()

    Used to convert a Date object, according to Greenwich time, to a string

    toUTCString()

    Used to convert a Date object, according to universal time, to a string

    toLocaleString()

    Used to convert a Date object, according to local time, to a string

    UTC()

    Starts with a date and returns the number of milliseconds from midnight of January 1, 1970 according to universal time

    valueOf()

    Used to return the primitive value of a Date object

    The GetFullYear() Method

    The GetFullYear() method retrieves a four-digit number representing a year. It is always used alongside a Date Object.


    <html>

    <body>


    <script type="text/javascript">var d = new Date()

    document.write("The year is: ")

    document.write(d.getFullYear())

    document.write("<br />")

    document.write("I was born in: ")

    document.write(d.getFullYear() -30)

    </script>

    </body>

    </html>

    The program is pretty simple to follow. It extracts the year and appends it to several sentences. In the final sentence, it subtracts 30 from the current date by using the code document.write(d.getFullYear() -30). The result of this program is:

      The year is: 2007
      I was born in: 1977

    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

    - A Closer Look at Smart Markers with Yahoo! M...
    - Using Polylines and Smart Markers with Yahoo...
    - Bulleted Menu of Links
    - Creating Click Loggers and Basic Markers wit...
    - Adding Pan Controls to Yahoo! Maps
    - Adding Zoom Controls to Yahoo! Maps
    - Working with Yahoo! Maps
    - Building Image Zooming Controls with the DOM...
    - Working with Multiple Graphics for a Zoom Ap...
    - Improving an Image Zooming Application with ...
    - Zooming in on Images with JavaScript
    - JavaScript Date Objects: Universal Coordinat...
    - Javascript Objects: More Date Methods
    - JavaScript Objects: Dates
    - JavaScript Objects: Finishing Strings

    Iron Speed





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway