Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Javascript JavaScript getFullYear method

Related Tutorials


 
 

Share on Google+Share on Google+

JavaScript getFullYear method

Advertisement
JavaScript method getFullYear() returns present year. To illustrate getFullYear() method.

JavaScript getFullYear method

     

JavaScript method getFullYear() returns present year. To illustrate getFullYear() method here we have created a button in the HTML page when you click on this button it calls the function getFullYearFunc() as defined in the JavaScript's script tag.

 

 

 

 

 

 function getFullYearFunc(){
		var myDate = new Date(); 
	    	alert(myDate.getFullYear());
	    }

In the above function, we have taken current date into a variable myDate. Now "myDate.getFullYear()" would return 4-digit number which represents the current year.

Here is the full JavaScript code with HTML code as follows:

<html>
<head>
	<title>Get full year example</title>
	<script>
	function getFullYearFunc(){
			var myDate = new Date(); 
	    	alert(myDate.getFullYear());
	    	}
	</script>	
</head>
<body>
<div style="background: #ff9900; width:'100%';" 
    align="center">
  <font color="#0000ff" size="12pt">
	<b>Get Full Year Example</b>
  </font>
 </div>
  <center>
  <p>&nbsp;</p>
  <input type="button" onclick="getFullYearFunc();" 
         value="Get full year from date">
</center>
</body>
</html>

Output :

When you will click on the button labeled "Get full year from date", it will show the current year from the date into alert message.

You can also download code from the following link.

Download Source Code

     

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 7, 2009

Related Tutorials

Discuss: JavaScript getFullYear method  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com