0


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

3
  • Are you saying you want to display Mon Apr 13 2020 18:44:29 GMT+0530 as the input text of the Material DatePicker when you initialize it with the value 1998-02-02T18:30:00.000+0000? Please provide an minimal reproducible example with a clear description if this is not what you mean. Commented Apr 13, 2020 at 13:33
  • @Igor No, if I convert the received date from API to mentioned format which is "Mon Apr 13 2020 18:44:29 GMT+0530" the mat date picker will show the date. Commented Apr 13, 2020 at 13:37
  • It still sounds like you to display that to the end user. The actual data should always be handled/persisted as either some type of Date type or in ISO8601 notation if it is being communicated as a string. To display this format in the UI you need to specify the MAT_DATE_FORMATS. Commented Apr 13, 2020 at 13:43

1 Answer 1

1

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"))

Sign up to request clarification or add additional context in comments.

1 Comment

what if i need to parse it from dd/MM/yyyy to given fromat.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.