0

here is my date 10/04/2013 i convert it oct 4,2013.

<input type="text" required="required" name="dateofissue" id="dateofissue" readonly>

and here is javascript who get current date:

var now = new Date();
 document.getElementById("dateofissue").value=(now.getMonth()+1)+'/'+now.getDate()+'/'+now.getFullYear();

it shows date in format 10/04/2013.i want when it shows date in this format i get this date and converrt it in oct 4,2013

Fiddle Here

S. S. Rawat
  • 5,943
  • 4
  • 43
  • 59
Muhammad Arif
  • 1,014
  • 3
  • 22
  • 56
  • you have to declare an array of month like the one mentioned in this [link](http://stackoverflow.com/questions/1643320/get-month-name-from-date-using-javascript) – Anusha Oct 04 '13 at 05:26
  • or something like `toDateString()` http://www.w3schools.com/jsref/jsref_todatestring.asp – Anusha Oct 04 '13 at 05:28

7 Answers7

1

Try this:

var d1 = new Date();
var datestring = d1.toDateString().substring(4).split(' ');
var datestr = datestring[0]+' '+parseInt(datestring[1])+', '+datestring[2];
Tarun Singhal
  • 977
  • 8
  • 11
0

you can try like this.

var d1 = new Date();
var datestring = d1.toDateString().substring(4).split(' ').join(',').replace(',',' ').replace('0','');
alert(datestring);
sudhansu63
  • 6,025
  • 4
  • 39
  • 52
0

Try this:

var now =new Date().toDateString();
var date = now.split(' ');
var formattedDate=date[1]+" "+parseInt(date[2])+","+date[3];
document.getElementById("dateofissue").value=formattedDate;
arulmr
  • 8,620
  • 9
  • 54
  • 69
Vicky Gonsalves
  • 11,593
  • 2
  • 37
  • 58
0
var now = new Date();
var monthNamesL = [ "January", "February", "March", "April", "May", "June",
                    "July", "August", "September", "October", "November", "December" ],
    monthNamesS = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];

var dateFmtd = monthNamesS[now.getMonth()] + ' ' + now.getDay() + ', ' + now.getFullYear();

document.getElementById("dateofissue").value = dateFmtd;

http://jsfiddle.net/daCrosby/3VqAK/

DACrosby
  • 11,116
  • 3
  • 39
  • 51
0

I would recommend using moment.js

It also has a host of other useful features.

Mandeep Jain
  • 2,304
  • 4
  • 22
  • 38
0

If you are open to use external library then I would prefer to use

Moment.js

moment().format("MMM, D YYYY");  //Oct 4,2013
Praveen
  • 55,303
  • 33
  • 133
  • 164
0

This will give you the format you need

var now = new Date();
$.datepicker.formatDate("M d,yy", now);
Abhishek
  • 411
  • 8
  • 19