question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor WASM input time fails to show values after upgrade to .NET 5

See original GitHub issue

This issue has been moved from a ticket on Developer Community.


[severity:It’s more difficult to complete my work] [regression] [worked-in:3.1] I have a Blazor WASM project that I just have upgraded to .NET 5. After upgrade my input time:



@code{
    DateTime myTime = DateTime.Now.ToLocalTime();
    string myTimeFormat = "HH:mm:ss"; 
}

only shows “–:–” instead of the time on the format “HH:mm:ss” that it used to do.

Chrome (and Edge) console prints.

blazor.webassembly.js:1 The specified value “12.52.58” does not conform to the required format. The format is “HH:mm”, “HH:mm:ss” or “HH:mm:ss.SSS” where HH is 00-23, mm is 00-59, ss is 00-59, and SSS is 000-999.

I posted this as question on SO


Original Comments

Feedback Bot on 2/19/2021, 07:18 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Andrzej-Wcommented, Mar 24, 2021

In my opinion Blazor WASM works correctly (binding to input type="time") and this issue can be closed.

Unfortunately there are some differences in culture definitions in various environments (Windows 10, Windows Server, Linux, WASM). What is the moral of the story? Whenever you exchange data between different systems, you must use culture-independent date, time, and number formatting, even if you are sure that both systems are set to the same culture.

1reaction
Andrzej-Wcommented, Mar 24, 2021

@erikthysell run this code to understand the difference between culture dependent and culture independent formatting.

@page "/"
@using System.Threading
@using System.Globalization

<h1>Date and time formatting</h1>

<button class="btn btn-primary" @onclick=@UpdateTime1>Update time en-US</button>
<button class="btn btn-primary m-2" @onclick=@UpdateTime2>Update time da-DK</button>
<input type="time" @bind="myTime" @bind:format=@myTimeFormat />

<div class="alert alert-primary mt-2">Culture dependent formatting: @myTime.ToString(Format1)</div>
<div class="alert alert-primary">Culture independent formatting: @myTime.ToString(Format2)</div>
@code
{
  // Please note that / (slash) will be replaced by culture dependent date separator
  // and : (colon) will be replaced by culture dependent time separator.
  // Letter T is not reserved character and will be included in the output string unchanged
  // (you don't have to use apostrophes around capital letter T)
  // Read section "Date and time separator specifiers" and "Character literals" here:
  // https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings#date-and-time-separator-specifiers

  private const string Format1 = "yyyy/MM/ddTHH:mm:ssK";      // string with culture dependent placeholders
  private const string Format2 = "yyyy-MM-ddTHH':'mm':'ssK";  // string with literals - you have to use ' (apostrophe) around colon
  DateTime myTime = DateTime.Now;
  string myTimeFormat = "HH':'mm':'ss";  // use apostrophes around colons, otherwise colon will be replaced by culture dependent time separator

  private void UpdateTime1()
  {
    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
    myTime = DateTime.Now;
  }
  private void UpdateTime2()
  {
    Thread.CurrentThread.CurrentCulture = new CultureInfo("da-DK");
    myTime = DateTime.Now;
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Blazor WASM .NET 5 input time do not show correctly
Chrome console prints the following: blazor.webassembly.js:1 The specified value "12.52.58" does not conform to the required format. The format ...
Read more >
ASP.NET Core Blazor forms and input components
Learn how to use forms with field validation and built-in input components in Blazor.
Read more >
Handle errors in ASP.NET Core Blazor apps
This article describes how Blazor manages unhandled exceptions and how to develop apps that detect and handle errors.
Read more >
Cannot debug net6.0-macos Apps - Developer Community
When I hit debug, the following error is shown in the Terminal: Possible reasons for this include: * You misspelled a built-in dotnet...
Read more >
How to Build and Secure Web Applications with Blazor
Learn how to build client-side Web apps using Blazor and how to secure them with Auth0 authentication and authorization features.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found