convert string to Time format in typescript
Solution 1
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'
Solution 2
Here you need to use momentjs.
1st Step:
npm install moment
ts
import * as moment from 'moment';
2nd Step:
moment({ // Options here }).format('hh:mmA')
ionMobDev
Interested to keep tracking on new challenges and supporting to resolve the critical bugs until resolving the issues.
Updated on July 16, 2022Comments
-
ionMobDev almost 2 years
I have to convert my server data in string format as
13:47
to01:47PM
but am trying with{{time | date:"hh:MM"}}
and{{task.time | date: 'shortTime'}}
but it showing an datepipe error and arugument errorRuntime Error
InvalidPipeArgument: '13:17' for pipe 'DatePipe'
-
Niladri over 6 yearscan you post your code ?
-
Niladri over 6 yearsthe 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).
-