title: How to get specific year from the Date field in jquery
body: <p>I know its a bit silly question, but I actually wanted to know how can I retrieve the year value for a date that I already have without using the "Split" function. I can achieve it with the help of the "split" function. Below is the code that I used in jquery.</p>
  
  <pre class="lang-js prettyprint-override"><code>outputJSon = JSON.parse($('#' + Datepicker_id).val());
  var currentYear = parseInt(CalculateYearfromString($('#' + currentActivityCalendarId).parents('.service-timeline').find('.membership-year .period').text()));
  
  if (currentYear === undefined &amp;&amp; $.trim(currentYear) === "")
    currentYear = new Date().getFullYear();
  
  if (parseInt(outputJSon["Date"].split('/')[0]) === currentYear)
    outputDate = outputJSon["Date"];
  else
    outputDate = outputJSon["Date"].replace(outputJSon["Date"].split('/')[0], currentYear)
  
  outputDateType = outputJSon["DateType"];
  </code></pre>
  
  <p>In the above code, I am retrieving the date value in a JSON format which returns <strong>Date eg. 2016/05/26</strong> and <strong>DateType eg. Day</strong>. </p>
  
  <p>I am fetching the current year that I have selected and then checking if <strong>currentYear</strong> value is equal to the year that I have in the <strong>outputJSon["Date"]</strong>. If there is a match, then I am replacing the <strong>[0]</strong> value of the <strong>outputJSon["Date"]</strong> with the <strong>currentYear</strong>, with the help of <strong>replace</strong> function. This works as expected and no error is encountered.</p>
  
  <p>I just want to be sure that if the date format changes(<strong>from 2016/05/26 to 26/05/2016)**then the split function that I have written will retrieve wrong value. How can I avoid this. Shall I remove **split</strong> function and think of something else?</p>
  
  <p>Any help is appreciated.</p>
  
  <p>Thanks,</p>