Reputation: 1022
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
Upvotes: 0
Views: 628
Reputation: 433
This will give you the format you need
var now = new Date();
$.datepicker.formatDate("M d,yy", now);
Upvotes: 0
Reputation: 56509
If you are open to use external library then I would prefer to use
moment().format("MMM, D YYYY"); //Oct 4,2013
Upvotes: 0
Reputation: 1007
Try this:
var d1 = new Date();
var datestring = d1.toDateString().substring(4).split(' ');
var datestr = datestring[0]+' '+parseInt(datestring[1])+', '+datestring[2];
Upvotes: 1
Reputation: 2664
I would recommend using moment.js
It also has a host of other useful features.
Upvotes: 0
Reputation: 11460
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/
Upvotes: 0
Reputation: 6190
you can try like this.
var d1 = new Date();
var datestring = d1.toDateString().substring(4).split(' ').join(',').replace(',',' ').replace('0','');
alert(datestring);
Upvotes: 0
Reputation: 11717
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;
Upvotes: 0