While working on my Angular2 application, I noticed that all the dates returned by my controller are in the format "2017-02-2700:00:00". I wanted to customize the way Date objects are created so that I can remove the T from the string while still maintaining the functionality of a date object. However, my current approach of creating an extended IDate object is not working as expected - it's showing up as null instead of a valid date object. Does anyone have any insights into what might be causing this issue and how to resolve it? I'm open to using ES6 JavaScript if TypeScript doesn't offer a solution. I came across a helpful post about extending the Date object, but I was hoping to create my own custom object called IDate with additional methods without modifying the original Date object. If that cannot be achieved, I'll consider marking that post as the answer.
export class IDate extends Date {
constructor() {
super();
}
value;
toDate(value: string): Date {
value.replace("T", " ");
return new Date(value);
}
getvalue() {
return this.value;
}
}
let t = new IDate();
let d = new Date();
console.log(t);
console.log(d);
console
IDate {}
Fri Mar 31 2017 11:53:59 GMT-0500 (Central Daylight Time)