How to convert yyyy-mm-dd formatted date to 'long date' format using jquery?

后端 未结 4 1165
故里飘歌
故里飘歌 2021-01-22 13:18

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 for

相关标签:
4条回答
  • 2021-01-22 13:48

    var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    
    var current_date = new Date("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

    0 讨论(0)
  • 2021-01-22 13:56

    I'd use the Moment.js library for this purpose:

    console.log(moment("2015-07-15").format("DD MMMM YYYY")); //prints 15 July 2015
    <script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script>

    0 讨论(0)
  • 2021-01-22 14:08
    var months=["jan","feb","march","April","may","jun","july","August","sept","oct","nov","dec"];
    var dateValue=new Date();
    var date=dateValue.getDate();
    var year=dateValue.getFullYear()
    console.log("Today is :"+date+ "  "+months[dateValue.getMonth()]+"   "+year);
    
    0 讨论(0)
  • 2021-01-22 14:13

    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

    0 讨论(0)
提交回复
热议问题