0

Currently date is displaying as in this format Sun Jan 01 2012 00:00:00 GMT+0530 (India Standard Time), Can we display it just like Jan 2012? I want to display this date into Month Year(Jan 2012) format.

   
   
     $(document).ready(function(){
     var ddate = new Date('January 01, 2012 00:0:00');
     
     document.getElementById('test').innerHTML = ddate;
      
     });
    
      
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="test"></div>

Can anyone help me to fix it?

Jasbir
  • 374
  • 5
  • 15
  • You might want to check this question and the answers: https://stackoverflow.com/q/1056728/3000771 – rolfv1 Jan 18 '18 at 07:46
  • This is a great answer: https://stackoverflow.com/a/10685571/295783 – mplungjan Jan 18 '18 at 07:48
  • @mplungjan sorry to say you, but i am not capable to find the answer. Can you please help ? – Jasbir Jan 18 '18 at 07:50
  • you can do like this. var options = { year: 'numeric', month: 'short'}; var ddate = new Date('January 01, 2012 00:0:00'); ddate.toLocaleDateString("US", options); – suresh kumar Jan 18 '18 at 07:56
  • Thanks @sureshkumar – Jasbir Jan 18 '18 at 08:02
  • @jasbir: There are 48 answers in the duplicate - one of them should be useful to you. If not then `var parts = ddate.split(" "); console.log(parts[1]+" "+parts[3]);` – mplungjan Jan 18 '18 at 08:06

0 Answers0