CodeDonkey CodeDonkey - 1 month ago 10
TypeScript Question

ng2-chart date is displayed as unix timestamp

I am importing a date

Object
from my database. Unfortunately the date is displayed as an
Unix
timestamp
(-62101391858000)
. I am aware of the possibility to format my date via
pipes
like this:
{{myDate | date:medium}}
but I am using
ng2-charts
and therefore I have to solve this in another way.
My chart is displayed like this:

<base-chart class="chart"
[datasets]="lineData"
[labels]="lineLabels"
[options]="lineChartOptions"
[colors]="lineChartColours"
[legend]="lineChartLegend"
[chartType]="lineChartType">
</base-chart>


I tried to find
<base-chart>
but it is hidden somewhere in the
ng2-charts
magic.

Any suggestions on how to solve this?

Answer

I figured it out now, instead of trying to pipe the output in the frontend i simply did a typecast:

this.temp1.push(new Date(data[i]["truncStartTime"]).toLocaleDateString());

instead of:

this.temp1.push(data[i]["truncStartTime"]);