I have a time stamp like
2021-03-12T14:55:35.454Z
I want to convert that into normal time like this (below) in the ts file
2:55pm
I am working in angular. Please help if you guys know. I have tried searching other stackoverflow questions but I couldn’t find the exact solution
Please help if you guys know
Advertisement
Answer
Use, Angular’s built-in DatePipe.
if you want to use it in html
JavaScript
x
2
1
{{ yourDate| date: 'shortTime'}}
2
or in component file:
JavaScript
1
2
1
const myDate = new DatePipe('en-US').transform(rawDate,'shortTime' );
2
rawDate is your complex timestamp.
to know more about formats available , head on to https://angular.io/api/common/DatePipe