Reputation: 1079
I have array of items. inside that i have objects Please find the structure of one JSON object.
[{ApprovedBy: ""
ApprovedDate: "10/12/2019 7:27:24 AM"
AssignedTo: null
ChildClashes: [{_ClashPoint: {X: "0", Y: "0", Z: "0"},…}, {_ClashPoint: {X: "0", Y: "0", Z: "0"},…},…]
ClashFoundDate: "9/12/2019 7:27:24 AM"
ClashID: "109d3ee3-d470-4534-ac72-0b4f2c3c90eb"
ClashImage: null
ClashName: "New Group"
ClashPublishedBy: "Srini"
ClashStatus: "Reviewed"
Comments: null
Description: "Hard"
Distance: "-2.5"
GroupID: null
ID: 456
ImagePath: null
IsGroup: true
Item1: null
Item2: null
RevisionID: "1"
Viewpoint: ""},
........]
so i want to change the format of approveddate and clashfounddate to dates with MM/dd/YYYY format. Please let me know how to do it. please reduce the for loops as much as possible. thanks in advance.
Upvotes: 0
Views: 601
Reputation: 10429
Inject date pipe in construtor like
constructor(
private datePipe:DatePipe
)
and then
yourdata.forEach(d=>{
d.ClashFoundDate=this.datePipe.transform(d.ClashFoundDate,'MM/dd/yyyy')
d.ApprovedDate=this.datePipe.transform(d.ApprovedDate,'MM/dd/yyyy')
})
Upvotes: 1