Format date/time using .NET instead of JavaScript function #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theDateTime
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 theToShortDateString
of theDataTime
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.