I have datetime data get from my db, raw data datetime is 2019-04-02T17:14:54.204515Z
In view Component, I using {{acc.updated_at|date:'dd/MM/yyyy HH:mm:ss'}}
but my result I received is 03/04/2019 00:14:54
. Correct result is 02/04/2019 17:14:54
May I have wrong in my code? Thanks for help!
Asked
Active
Viewed 1,260 times
-2

Virtus
- 67
- 1
- 2
- 6
-
1Possible duplicate of [Format date as dd/MM/yyyy using pipes](https://stackoverflow.com/questions/35754586/format-date-as-dd-mm-yyyy-using-pipes) – Harun Yilmaz Apr 02 '19 at 10:33
-
sorry, I already updated my solution! I saw it but not work to me – Virtus Apr 02 '19 at 10:40
2 Answers
0
you can do this by:
<table width="100%" border="1">
<tr>
<th colspan="2">Test format Date Angular</th>
</tr>
<tr>
<th>Date</th>
<th>Format</th>
</tr>
<tr>
<th colspan="2">Model Date ({{dateNow}})</th>
</tr>
<tr *ngFor="let format of formatsDateTest">
<td>{{dateNow | date: format}}</td>
<td>{{format}}</td>
</tr>
<tr>
<th colspan="2">Model string ISO ({{dateNowISO}})</th>
</tr>
<tr *ngFor="let format of formatsDateTest">
<td>{{dateNowISO | date: format}}</td>
<td>{{format}}</td>
</tr>
<tr>
<th colspan="2">Model Number Milliseconds ({{dateNowMilliseconds}})</th>
</tr>
<tr *ngFor="let format of formatsDateTest">
<td>{{dateNowMilliseconds | date: format}}</td>
<td>{{format}}</td>
</tr>
</table>
and in .ts
formatsDateTest: string[] = [
'dd/MM/yyyy',
'dd/MM/yyyy hh:mm:ss',
'dd-MM-yyyy',
'dd-MM-yyyy HH:mm:ss',
'MM/dd/yyyy',
'MM/dd/yyyy hh:mm:ss',
'yyyy/MM/dd',
'yyyy/MM/dd HH:mm:ss',
'dd/MM/yy',
'dd/MM/yy hh:mm:ss',
];
dateNow : Date = new Date();
dateNowISO = this.dateNow.toISOString();
dateNowMilliseconds = this.dateNow.getTime();

Muhammad Ali
- 369
- 7
- 23
-1
you can format date by using date
filer in html like this
First solution
<span>{{created |date:'dd.MM.yyyy, hh:mm'}}</span>
Or you can format it in ts file
Second solution
toDate = new Date();
let toDate=(this.toDate.getDate()+1)+"/"+this.toDate.getMonth()+"/"+this.toDate.getFullYear();
by use Date object function (get Month ... etc)
Update
Your issue is from zone and you should display hour in 24 not 12 system plz see here you can find the solution How can I deal with the timezone issue with the Angular 4 date pipe?

Kenana Reda
- 430
- 1
- 9
- 24
-
Colud you add ts code or What the type of acc.updated_at ? Is it Date Object? @Virtus – Kenana Reda Apr 02 '19 at 10:41
-
My purpose is to convert the Date data I received from the database to the dd.mm.yyy format, I tried all, but I received wrong date time. I think need to config time zone, but I don't know how to config – Virtus Apr 02 '19 at 10:54
-
-
yeah I see, pls have a look on updated answer, I've put a link to fix zone issue – Kenana Reda Apr 02 '19 at 10:58