Example of Time Format in ASP.NET MVC TimePicker Control
The TimePicker has been customized with 24-hour format with 60 minutes interval. Click/Touch the TimePicker popup icon to a select a time from 00:00 to 23:00 from the TimePicker popup.
@Html.UiTimePicker("timepicker", new UiTimePickerOptions { Format = "HH:mm", Step = 60, Value = ((DateTime)ViewData["value"]).TimeOfDay })
<style>
.control_wrapper { display: block; margin: 0 auto; max-width: 300px; padding: 5% 0; }
.tabs-wrap { padding: 0 0 10px; }
</style>
<div class="control-section">
<div class="control_wrapper">
<div class="tabs-wrap">
<div class="wrap">
@Html.UiTimePicker("timepicker", new UiTimePickerOptions { Format = "HH:mm", Step = 60, Value = ((DateTime)ViewData["value"]).TimeOfDay })
</div>
</div>
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class TimePickerController : Controller
{
// The page is Views/TimePicker/TimeFormat.cshtml; it draws what ViewData holds.
public ActionResult TimeFormat()
{
ViewData["value"] = DateTime.Now;
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
TimePicker provides an option to customize the display format of the time value using the format property. It accepts standard & custom date and time format strings as specified in MSDN.
Here, the time value displayed in 24-hour format with 60 minute step interval. To know more about custom time formatting, refer the Parsing and formatting section. By default, TimePicker component is formatted with `en` (English) culture.