Javascript – extract Year from Date

Author - Webner
22.02.2015
|
0 Comments
|

If you want to extract the year from Date in Javascript, try getFullYear() method instead of getYear(), see the output below on Firefox and Chrome:

Here’s the code:

<html>
<head>
<script langauge="javascript">
var date1 = new Date();
var browser = navigator.userAgent;
var dateMessage = "I am on "+browser+"nnCurrent Date : "+
date1;
dateMessage += "ndate1.getYear()>> "+date1.getYear()+
"ndate1.getFullYear()>> "+date1.getFullYear();
alert(dateMessage);
</script>
</head>
</html>

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *