if (Convert.ToDateTime(GrdEmployeeAttendance.CurrentRow.Cells["LoginTime"].Value) < Convert.ToDateTime(GrdEmployeeAttendance.CurrentRow.Cells["LogoutTime"].Value))
{
if (GrdEmployeeAttendance.Columns[e.ColumnIndex].Name == "LoginTime")
{
GrdEmployeeAttendance.EndEdit();
if (Convert.ToDateTime(GrdEmployeeAttendance.CurrentRow.Cells[e.ColumnIndex].Value) < Convert.ToDateTime("01:00 PM"))
{
GrdEmployeeAttendance.CurrentRow.Cells["CheckFN"].Value = true;
}
else
{
GrdEmployeeAttendance.CurrentRow.Cells["ChkAN"].Value = true;
}
}
}
1 回答
0
要将登录时间与注销时间进行比较,您将需要使用DateTime.Compare方法。
它接受两个参数(DateTime要比较的对象的两个实例),并返回一个整数,指示第一个是早于、相同还是晚于第二个。
如果第一次较早,则返回值小于0。如果两个时间值相同,则返回值为0。如果第一次较晚,则返回值大于零。
示例代码:
DateTime date1 = new DateTime(2009, 8, 1, 0, 0, 0);
DateTime date2 = new DateTime(2009, 8, 1, 12, 0, 0);
int result = DateTime.Compare(date1, date2);
string relationship;
if (result < 0)
relationship = "is earlier than";
else if (result == 0)
relationship = "is the same time as";
else
relationship = "is later than";
Console.WriteLine("{0} {1} {2}", date1, relationship, date2);
// The example displays the following output:
// 8/1/2009 12:00:00 AM is earlier than 8/1/2009 12:00:00 PM
于 2011-02-16T05:51:07.377 回答