Home arrow JavaScript arrow 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
(Page 1 of 5 )

 

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


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- 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
- Dynamic jQuery Styling

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 4 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials