Muhammad Arif
Muhammad Arif

Reputation: 1022

how to convert date format from 10/04/2013 to Oct 4,2013

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

Answers (7)

Abhishek
Abhishek

Reputation: 433

This will give you the format you need

var now = new Date();
$.datepicker.formatDate("M d,yy", now);

Upvotes: 0

Praveen
Praveen

Reputation: 56509

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

Moment.js

moment().format("MMM, D YYYY");  //Oct 4,2013

Upvotes: 0

Tarun Singhal
Tarun Singhal

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

Mandeep Jain
Mandeep Jain

Reputation: 2664

I would recommend using moment.js

It also has a host of other useful features.

Upvotes: 0

DACrosby
DACrosby

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

sudhansu63
sudhansu63

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

Vicky Gonsalves
Vicky Gonsalves

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

Related Questions