1

I am quite new to ASP.Net Core MVC. I am trying to display the current time in input type time. But I am not able to do so. Below is the code I am trying.

  <input type="time" id="starttime" value="@DateTime.Now.ToString("hh::mm::ss tt")" />

The time picker shows blank. I also tried by setting time by script but no luck.

Could someone please help? Isnt it possible to display current time in this manner?

1
  • Q: Is your question answered/your problem resolved? Commented Nov 10, 2021 at 15:39

1 Answer 1

0

Per the documentation: "The control's user interface varies from browser to browser".

SUGGESTIONS:

  1. Look at the actual HTML rendered in Chrome Dev Tools.
  2. If the HTML looks OK, experiment with different ".ToString()" format patterns until your time picker looks OK, too.
  3. Once it works on one browser (e.g. Chrome), be sure to also test on other browsers (e.g. IE11, Firefox, Safari and Edge).

FYI, I don't think the format "hh::mm::ss tt" is valid for any browser.

I tried these different format strings on Chrome:

Format         Status  Display:
------         ----    -------
hh::mm::ss tt  FAILS   --:-- --
hh:mm          OK      12:33 PM
hh:mm:ss       OK      12:33:38 PM
hh:mm:ss tt    FAILS   --:-- --
hh::mm         FAILS   --:-- --
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the update. I see that hh:mm works for chrome.
IMPORTANT POINTS: 1) "hh:mm" should work for ANY browser.On the other hand, "hh::mm::ss tt" is NOT a valid time format, and probably WON'T display a time value in most (all?) browsers. 2) As a web developer, you'll need to make it a point to ALWAYS test on MULTIPLE DIFFERENT BROWSERS. ALSO: Please feel free to "upvote" and/or "accept" the answer if you found it helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.