0

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”);
1
  • Hi Neelima and welcome, do you mind showing us your code? Commented Apr 5, 2021 at 12:54

2 Answers 2

1

The amParse pipe that exists in ngx-moment is a good candidate for this. https://www.npmjs.com/package/ngx-moment#amparse-pipe

Parses a custom-formatted date into a moment object that can be used with the other pipes.

The output of that pipe behaves pretty much like a date and can also be used with other pipes to output it as a specific format like you're looking to do. If you only want it in code and not in HTML, you can use some of the functions in the underlying moment.js library: https://momentjs.com/docs/#/parsing/

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

Comments

0

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

Comments

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.