How to add current date in (dd/mm/yy) format and time (hh:mm:ss) in asp.net MVC web application 2019
What to write in cide for Model view & Controller for displaying current time and current date individually in ASP.NET Core MVC Web Application 2019( E Commerce )


Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 12, 2023, 4:54 AM EST
Hello Suman,
Write blow code:
Model:
public class DateTimeModel { public string CurrentTime { get; set; } public string CurrentDate { get; set; } }Controller :
public class DateTimeController : Controller { public IActionResult Index() { DateTimeModel model = new DateTimeModel { CurrentTime = DateTime.Now.ToString("hh:mm tt"), CurrentDate = DateTime.Now.ToString("dd/MM/yyyy") }; return View(model); } }View:
Thanks
Naimish Makwana