'How to convert seconds to minutes in MVC?
I get the input as a second from the user and I want to show it as minutes and second in the Grid. I know I have to use a method but I don't know how.
**SeizureViewModel**
[Display(Name ="Seizure Time")]
public int SeizureTime{ get; set; }
**AddSeizure View**
@Html.BSMaterialTextBoxFor(model => model.SeizureTime, "", colCSS: "col-6")
**Show Seizure View**
@model PagedList<SeizureViewModell>
<div class="row">
<div class="col-xs-12">
@(Html.Grid(Model)
.Name("epileptic seizures")
.PKColumn(p => p.ID)
.Columns(c =>
{
c.Add(a => a.SeizureTime);
}).HasHeader(true)
.HasFooter(true)
.ToolbarButtons(b => { b.Add(GridButtonType.custom).CssClass("btn addseizure").Icon("fa-plus").Title("Add Epilectic Seizure"); })
)
</div>
</div>
Solution 1:[1]
In ViewModel , I added an another property to show the time the way I want to.
public string SeizureTimeStr
{
get
{
return (SeizureTime/ 60).ToString() +" Minutes"+ " " + (SeizureTime% 60).ToString()+" Seconds";
}
}
This is where I show the seizure time so I changed it as SeizureTimeStr in ShowSeizureView.
<div class="col-xs-12">
@(Html.Grid(Model)
.Name("epileptic seizures")
.PKColumn(p => p.ID)
.Columns(c =>
{
c.Add(a => a.SeizureTimeStr);
}).HasHeader(true)
.HasFooter(true)
.ToolbarButtons(b => { b.Add(GridButtonType.custom).CssClass("btn addseizure").Icon("fa-plus").Title("Add Epilectic Seizure"); })
)
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | vives |