The standard MVC pattern passes a view model to a View. You get to format the date however you like within the view's HTML (Razor).
Standard date and time format strings
Custom date and time format strings
Get started with ASP.NET Core MVC
namespace MvcBasic.Controllers
{
public class ViewModel
{
public DateTime dateTime { get; set; }
}
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
ViewModel vm = new ViewModel() { dateTime = DateTime.Now };
return View(vm);
}
}
}
View
@model MvcBasic.Controllers.ViewModel
@{
ViewData["Title"] = "Index";
}
<h1>Index</h1>
<h4>ViewModel</h4>
<hr />
<table>
<tr>
<td>
DateTime: @Model.dateTime.ToString("MM/dd/yyyy hh:mm tt")
</td>
</tr>
</table>