Format date/time using .NET instead of JavaScript function
If you are interested.
The thinking might be, "I'm working in .NET with Blazor why then date and time formatting done in some other fashion that is not congruent with .NET." At least it was for me. One less thing to learn when I know .NET formating.
This is to address that issue, make formatting similar to .NET DateTime. My solution is to create .NET methods and call them from JavaScript. The challenge was having to create a date/time string that could be passed between JavaScript and .NET that would not assume the value as UTC and eliminate any type of conversion. The time zone offset also needs to be passed back to .NET methods for the same reason and to maintain the browser time without converting to server time. I used DateTimeOffset to solve some of these challenges along with formatting the time in JavaScript to ISO 8601 WITH the time zone of. One might exist but I could not find it, anything I found would convert to UTC.`
Now that the converting a date/time to a string is using the ToString() of the DateTime all of the standard .NET formatting should work. Standard date and time format strings.
I also incorporated a means to use the methods on the DataTime by way of reflections. For example, Format="ToShortDateString" to call the ToShortDateString of the DataTime object. You can call any of the methods, ToLongDateString, ToLongTimeString, or any other that returns a string. This is not completely tested and might need some work.
I also did some updates to .NET 6.0 but not a complete project renaming.
If you are interested, I can continue to clean up the code for .NET 6.0 and test other DataTime string methods.
Hello Guy,
In hindsight I should have named this library BlazorServerTime.
The issue with calling DotNet.invokeMethodAsync for each html time node is that it can be a big hit when there are a lot of times on one page (for example in a table).
And I'm just now seeing that as I take this out of the lab and try it for real use. A column with date/times is all blank then the date time pops in after rendering. Something to work on.
Dohhh! Two columns one is using the updates the other is just showing the date. Typical programming, I solve one problem and I cause another.
