/// <summary>
/// 时间差
/// </summary>
/// <param name="type">要获取的时间类型</param>
/// <param name="startDate">开始时间</param>
/// <param name="endDate">结束时间</param>
/// <returns></returns>
public static decimal DateDiff(string type, System.DateTime startDate, System.DateTime endDate)
{
decimal diff = 0;
System.TimeSpan TS = new System.TimeSpan(endDate.Ticks - startDate.Ticks);
switch (type.ToLower())
{
case "year":
diff = StringUtil.GetDecimal(TS.TotalDays / 365);
break;
case "month":
diff = StringUtil.GetDecimal((TS.TotalDays / 365) * 12);
break;
case "day":
diff = StringUtil.GetDecimal(TS.TotalDays);
break;
case "hour":
diff = StringUtil.GetDecimal(TS.TotalHours);
break;
case "minute":
diff = StringUtil.GetDecimal(TS.TotalMinutes);
break;
case "second":
diff = StringUtil.GetDecimal(TS.TotalSeconds);
break;
}
return diff;
}
C#两个时间之间的差值
最新推荐文章于 2024-06-04 17:13:58 发布