Issue
I have an Ionic Mobile App where i receive data from localstorage.
I want to display the milliseconds in to date format. I am following the below code but not able to get the result. Please suggest where i am doing the mistake
Localstorage has data as below:
{"data":[[0,"1599843000000"],[1,"1599929580000"],[2,"1600448100000"],[3,"1599843360000"],[4,"1599843420000"],[5,"1599843420000"]]}
1599843000000 is milliseconds
Now i want to display all the records in date time format like below.
Fri 11 September 2020 22:20:00
my home.html looks like below:
<ng-container *ngFor="let item of items[0]" >
<ion-item no-lines *ngIf='this.items!= 0'>
<ion-row>
<ion-col>
<h3 ion-text>
{{item [0]}}
</h3>
</ion-col>
<ion-col>
<h3 ion-text>
{{item [1]}}
</h3>
</ion-col>
</ion-row>
</ion-item>
</ng-container>
my home.ts for saving the data in localstorage looks like below:
if(!localStorage.getItem("dataset"))
{
var dataset = {data: []};
localStorage.setItem("dataset", JSON.stringify(dataset));
}
my home.ts for retrieve the data from localstorage looks like below:
var datasetData = localStorage.getItem("dataset");
let datasetArray = JSON.parse(datasetData );
this.datasetlength= dataset.data.length;
var dataArray = new Array();
for (var i=0;i<this.datasetlength;++i){
dataArray [i] = datasetArray .data[i];
}
var dataArraysortedarray = dataArray ;
this.items.push(dataArraysortedarray );
Solution
You can use the Angular Date pipe.
In your case,
{{ Number(item [1]) | date:'medium' }}
There are a lot of formats you can use.
Answered By - sidthesloth
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.