angularangular-materialangular-material-datetimepicker

how to parse date yyyy-MM-dd in angular 8



I am using the MatDatePicker for the Selecting date and showing the date in the edit mode of the application.

Now My API is returning me the date in following format which is not working in Edit mode.

"1998-02-02T18:30:00.000+0000"

How can we convert this into Mon Apr 13 2020 18:44:29 GMT+0530


Solution

  • use this. U have isos date string u need to convert date and take as string

     toDateString(param){
          return new Date(param).toString()
     }
     // for dd/mm/yyyy
     toDateFormat(param){
         var date1 = param.split('/')
         return  new Date(date1[1] + '/' +date1[0] +'/' +date1[2]).toString();
    }
    
    console.log(this.toDateString("1998-02-02T18:30:00.000+0000"))
    

    for javascript demo to see result

      function toDateString(param){
            return new Date(param).toString()
        }
        
        console.log(toDateString("1998-02-02T18:30:00.000+0000"))