ASP.net - C# Set input type: datetime-local to current date

Viewed 24564

This is how I declared the text field on my aspx file:

<input type="datetime-local" class="form-control" id="inputDate" runat="server">

and on my aspx.cs file's page load:

inputDate.Value = DateTime.Now.ToString("MM/dd/yyyy hh:mm tt");

My goal is that when the page loads, inputDate field contains the current date with this "MM/dd/yyyy hh:mm tt" format

but it doesn't work. Nothing's happening.

4 Answers

html5 input datetime-local

var localDateTime = DateTime.Now.ToString("s"); 
inputDate.Value = localDateTime;
Related