How To Convert Yyyy-mm-dd Formatted Date To 'long Date' Format Using Jquery?
I have date in yyyy-mm-dd format. It is found to be ISO Date format. I need to convert it to Long Date format. eg: I have date as '2015-07-15'. The converted date format should be
Solution 1:
I'd use the Moment.js library for this purpose:
console.log(moment("2015-07-15").format("DD MMMM YYYY")); //prints 15 July 2015
<scriptsrc="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script>
Solution 2:
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var current_date = newDate("2015-07-15");
month_value = current_date.getMonth();
day_value = current_date.getDate();
year_value = current_date.getFullYear();
document.write("Converted date is : " +
day_value +" "+ months[month_value] + " " + year_value);
Check discussion and many other solution here : Get month name from Date
Solution 3:
var months=["jan","feb","march","April","may","jun","july","August","sept","oct","nov","dec"];
var dateValue=newDate();
var date=dateValue.getDate();
var year=dateValue.getFullYear()
console.log("Today is :"+date+ " "+months[dateValue.getMonth()]+" "+year);
Solution 4:
You can do it by using switch,
function getFormattedDate(input){
date = new Date(''+input+'T00:00:00Z');
var y=date.getFullYear();
var m=date.getMonth()+1;
var d=date.getDate();
var mmm="";
switch(m)
{
case 1:
mmm="Jan";
break;
case 2:
mmm="Feb";
break;
case 3:
mmm="Mar";
break;
case 4:
mmm="Apr";
break;
case 5:
mmm="May";
break;
case 6:
mmm="June";
break;
case 7:
mmm="July";
break;
case 8:
mmm="Aug";
break;
case 9:
mmm="Sept";
break;
case 10:
mmm="Oct";
break;
case 11:
mmm="Nov";
break;
case 12:
mmm="Dec";
break;
}
alert(d+' '+mmm+' '+y)
}
getFormattedDate("2015-07-15");
Working JSFiddle Example
Post a Comment for "How To Convert Yyyy-mm-dd Formatted Date To 'long Date' Format Using Jquery?"