JavaScript
  Home arrow JavaScript arrow Page 2 - JavaScript Objects: Dates
IBM developerWorks
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  
Actuate Whitepapers 
VeriSign Whitepapers 
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: Dates
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-02-04

    Table of Contents:
  • JavaScript Objects: Dates
  • The Prototype Property
  • The Date() Method
  • The GetDate() Method
  • The GetMonth() Method

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    JavaScript Objects: Dates - The Prototype Property


    (Page 2 of 5 )

    The Prototype property exists in the String Object. And again, it works in the same manner. It allows you to add a property or method to an object.


    <html>

    <body>


    <script type="text/javascript">


    function evilemperor(name,title,punishment)

    {

    this.name=name

    this.title=title

    this.punishment=punishment

    }

    var james=new evilemperor("James","Supreme Ruler","Goon Hand")


    evilemperor.prototype.salary=null


    james.salary="4 Bagillion Dollars!"

    document.write("Do not mess up or you will receive the mighty goon hand!")

    document.write("<br />")

    document.write("The Supreme ruler's salary is:")

    document.write("<br />")

    document.write(james.salary)


    </script>


    </body>

    </html>

    The above code results in:

      Do not mess up or you will receive the mighty goon hand!
      The Supreme ruler's salary is:
      4 Bagillion Dollars!

    First it creates variable named evilemperor and stores several values in it. Then it uses prototype to add another data placeholder, and assigns a value to salary. Finally it prints out a bunch of gibberish that I wanted it to say, resulting in the above. Viola!

    Next up are the Date Object Methods. But first, here they are in a magnificent table:

    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


    More JavaScript Articles
    More By James Payne


       · Thanks for dropping by. Here, in this tutorial, we begin our discussion of the...
     

    JAVASCRIPT ARTICLES

    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables
    - Assigning Background Colors Dynamically to Z...
    - Building Zebra Tables with CSS and JavaScript
    - JavaScript: Array Objects
    - 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...







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