I'm a bit unclear on whether you require assistance with the server side (seems like c#) or the client side (javascript)
Either way, one approach is to create a custom setter or use a mapping function to map data from a web API to the class.
While I haven't tested this code, the concept involves having a setter that processes the date.
Server/C# code:
public class TestClass {
private DateTime paymentDate;
public DateTime? PaymentDate {
get {
return paymentDate;
}
set {
this.paymentDate = DateTime.ParseExact(value, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
}
}
}
I have not tested the C# code, but it should point you in the right direction.
For the client side (JavaScript/TypeScript), you could implement something like this:
export class TestClass {
private _paymentDate: Date;
get paymentDate(): Date {
return this._paymentDate;
}
set paymentDate(value: string) {
this._paymentDate = new Date(value);
}
}
In this case, the parsing occurs within the setter, allowing you to avoid handling it directly when retrieving the value in your code.
You would then proceed as follows:
let myTestClass = new TestClass();
request.get('pathtoapi').then(function(result) {
myTestClass.paymentDate = result.payment.paymentDate;
})