我正在尝试计算加班时间
public ActionResult Attendence()
{
// Accessing database
var hour = db.Student_Attendence.ToList();
List<HoursSpent> hourlist = new List<HoursSpent>();
HoursSpent spent = new HoursSpent();
var entertime = spent.InTime;
foreach (var item in hour)
{
// since starttime is a string in the db and intime is DateTime.
item.Student.StartTime = Convert.ToString(entertime);
item.Student.Name = spent.Name;
item.DateTime = spent.Date;
var exittime = spent.OutTime;
item.Student.EndTime = Convert.ToString(exittime);
var totaltime = spent.Hourspent;
if (exittime != null)
{
totaltime = exittime - entertime;
}
hourlist.Add(item);
}
return View(hourlist);
}