I am trying to convert “1983-24-12” to December 24, 1983 using Javascript.
Do we have any ready made function in Javascript which makes this conversion same as simpledateformat in Java?
I am trying to avoid taking months in Arrays and then do the manipulation.
My Code is as below.
//For Date Format
months = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
dob = responseObj.data.personDetail.birthDate.split('-');
month = months[dob[1]];
responseObj.data.personDetail.birthDate = month +" "+dob[2] +","+dob[0];
Kindly help.
EDIT: Since you mentioned that you’re using Sencha, you can use
Ext.Dateto add advanced date formatting and parsing:You can find more information here: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Date
The two methods you might find useful are parse and format
Alternatively, JQuery UI’s DatePicker widget implements a very robust date parser and formatter, which can be used in your own code like this:
The relevant functions here are parseDate and formatDate.
There is one problem though, to use this you’ll have to include both JQuery and JQuery UI as scripts in your code, which is probably a little excessive for what you need, and the other answers may perhaps suit your needs better.