Home > Back-end >  How to display current daytime in html form .net
How to display current daytime in html form .net

Time:02-15

I have an html form that includes Time Created field, and i want to display current date and time in the form when loaded. Ive tried many .ToString() overloads and time formats and nothing seems to display the value.

<label asp-for="TimeCreated" ></label>
                    <input asp-for="TimeCreated"  value="@{DateTime.Now.ToString("DD-MM-YYYYThh:mm");}" />
                    <span asp-validation-for="TimeCreated" ></span>

CodePudding user response:

You can use DateTime.Today Here tt refers to AM/PM

@DateTime.Today.ToString("dd-MM-yyyy tt hh:mm")
                                   

CodePudding user response:

The answer was to define type="datetime-local" into the input tag.

  • Related