How to covert AM/PM time format to hour format in angular 2

MMR picture MMR · Mar 16, 2017 · Viewed 9.5k times · Source

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

Answer

hakany picture hakany · Mar 16, 2017

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/).