I have time like this '2:00 PM' and I want to get it like this '14:00'.Can anyone please help me.Thanks.
Asked
Active
Viewed 1.2k times
2 Answers
4
If you want to change format in the component part and not in the view you can use the datepipe as follow:
// import the datepipe
import { DatePipe } from '@angular/common';
// init DatePipe
constructor(private datePipe: DatePipe) {}
// use it like
this.datePipe.transform(myDate, 'HH:mm');
An other options would be to use for example angular2-moment (https://github.com/urish/angular2-moment/).

hakany
- 7,134
- 2
- 19
- 22
2
You can format the date using a pipe (|
) and date:"<format>"
.
AM / PM is represented as tt
in date formats.
{{time | date:"hh:mm tt"}}
So you can remove the AM / PM like this:
{{time | date:"hh:mm"}}

Koby Douek
- 16,156
- 19
- 74
- 103
-
Hi Koby Douek,I dont want to display it but need to send that format into db. – MMR Mar 16 '17 at 06:47
-
1Share your code pleas so I can see where's the problem – Koby Douek Mar 16 '17 at 06:49