It appears that the date format you are receiving from the server is incorrect. In order to convert it, you will need a valid date format.
To address this issue, I have created a workaround solution by implementing a myDateParser()
method. This method can convert your invalid date into a valid one.
your.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
modifiedTimestamp;
constructor(){
// Passing unformatted date
this.modifiedTimestamp = this.myDateParser('2018-01-01-12:12:12:123456');
}
/**
* Custom Date parser
*/
myDateParser(dateStr : string) : string {
// Converting to a valid date format - e.g., 2018-01-01T12:12:12.123456;
let date = dateStr.substring(0, 10);
let time = dateStr.substring(11, 19);
let millisecond = dateStr.substring(20)
let validDate = date + 'T' + time + '.' + millisecond;
console.log(validDate)
return validDate
}
}
your.component.html
<table>
<tr>
<td>{{modifiedTimestamp | date: 'yyyy-MM-dd'}}</td>
</tr>
</table>
View the solution on stackblitz
I hope this solution proves useful for you!