I'm building a component, and in the OnAfterRenderAsync I'm trying to invoke some javascript and pass an object, that contains a bunch of members, one of which is a DateTime data type.
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
var parameters = new
{
date = DateValue
};
await JSRuntime.InvokeVoidAsync("window.myfunction", _inputReference, parameters);
}
}
In my javascript I have tested the data type, and I know it's a string...
window.myfunction = (options) {
var t = typeof options.date;
console.log(t);
var d = new Date(options.date);
console.log(d);
}
Is there a better way to pass a date? I need to work with the value as a date object, but is this really the best way to convert to a Date object (using new Date())? This approach to conversion seems fragile because it means that the Date objects parsing is assuming the format that the server side used. I don't know if that is vulnerable to regional settings differences between the browser and the server.