3

I have time like this '2:00 PM' and I want to get it like this '14:00'.Can anyone please help me.Thanks.

MMR
  • 2,869
  • 13
  • 56
  • 110

2 Answers2

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