[Fixed] Unable to convert java date object to angular string format

Issue

I have saved java date object in JSON format in db as tue dec 31 00:00:00 SGT 2019
I want to convert this in Angular dd/MM/yyyy format.

I am using date pipe but it is giving invalid date pipe argument.

Please suggest any method to use that I can use to convert Angular side not in Java.

Below is the code i am tried for converting in Angular.

Public pipe=new Datepipe (‘en-US’);
this.newVal= this.pipe.transform(this.newVal,”dd/MM/yyyy”);

Solution

If the date from backend is always in the expected format, you could just hardcode the format for conversion

this.newVal = "tue dec 31 00:00:00 SGT 2019";
let temp = date.split(' ');

Public pipe=new Datepipe (‘en-US’);
this.newVal = pipe.transform(temp[5] +" " +temp[1]+" "+temp[2], "dd/MM/yyyy");

Leave a Reply

(*) Required, Your email will not be published