2

I have to convert my server data in string format as 13:47 to 01:47PM but am trying with {{time | date:"hh:MM"}} and {{task.time | date: 'shortTime'}} but it showing an datepipe error and arugument error

Runtime Error

InvalidPipeArgument: '13:17' for pipe 'DatePipe'

Sampath
  • 63,341
  • 64
  • 307
  • 441
ionMobDev
  • 351
  • 1
  • 4
  • 20
  • can you post your code ? – Niladri Nov 12 '17 at 13:32
  • 3
    the input of the date pipe should be `an expression which is a date object or a number (milliseconds since UTC epoch) or an ISO string (https://www.w3.org/TR/NOTE-datetime).` – Niladri Nov 12 '17 at 13:35

2 Answers2

2

From the documentation

https://angular.io/api/common/DatePipe

expression is a date object or a number (milliseconds since UTC epoch) or an ISO string (https://www.w3.org/TR/NOTE-datetime).

Angular Default DatePipe only has support for Date Objects or ISOStrings(). If you want to convert either into format '01:47PM', the format would be 'hh:mmA'

Community
  • 1
  • 1
Mohib Wasay
  • 311
  • 2
  • 13
1

Here you need to use momentjs.

1st Step:

Reference:

npm install moment

ts

import * as moment from 'moment';

2nd Step:

Reference:

moment({ // Options here }).format('hh:mmA')
Sampath
  • 63,341
  • 64
  • 307
  • 441