Javascript – extract Year from Date

| By Webner

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:

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

Leave a Reply

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