0

I am building an Angular 7 app that consumes a java REST API for its data. The API delivers some date information in JSON form: { "date_c": "2019-03-10T06:00:00Z[UTC]", "state": 1, "id": 1, "name": "Charles Brown ", "provider": "clar" }

so in Angular when im trying to use
const myObjStr = JSON.stringify(jsonObject);

it display an error , i find out that the problem is in the symbols '[' and ']' of the [UTC], how can i remove it so it can work?

thanks in advance

1 Answer 1

1

Update:

Use slice pipe to truncate [UTC] before date formatting.

{{value | slice : 0:20| date:'d/M/yy, h:mm a' }}

Output:

Output

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

2 Comments

hi, yes i tryied to simplify , this is how i have it in the html component : <ngx-datatable-column name="Date" prop="date_c" [flexGrow]="2"> <ng-template let-row="row" let-value="value" ngx-datatable-cell-template> {{value | date:'d/M/yy, h:mm a'}} </ng-template> </ngx-datatable-column> , and the error in the web console is : Unable to convert "2019-03-10T06:00:00Z[UTC]" into a date' for pipe 'DatePipe
I tried to convert this date into an actual date object and I see Invalid Date error due to [UTC]. so I tried to truncate [UTC] by using Slice pipe and it works. Use this {{value | slice : 0:20| date:'d/M/yy, h:mm a' }}

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.