using System; using System.Globalization; namespace Common { /// <summary> /// 时间处理 /// </summary> public class DateTimeCommonHandler { /// <summary> /// 获取时间是一年的第几周 /// </summary> /// <param name="dt"></param> /// <returns></returns> public int GetWeekNum(DateTime dt) { GregorianCalendar gc = new GregorianCalendar(); int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday); return weekOfYear; } /// <summary> /// C#获取指定日期时间是当前年度的第几个季度 /// </summary> /// <param name="dt"></param> /// <returns></returns> public int GetQuarterNum(DateTime dt) { var mouth = dt.Month; int quarter = mouth % 3 == 0 ? mouth / 3 : (mouth / 3 + 1); return quarter; } /// <summary> /// 求时间段间隔天数 /// </summary> /// <param name="dateStart"></param> /// <param name="dateEnd"></param> /// <returns></returns> public int DateDiff(DateTime dateStart, DateTime dateEnd) { DateTime start = Convert.ToDateTime(dateStart.ToShortDateString()); DateTime end = Convert.ToDateTime(dateEnd.ToShortDateString()); TimeSpan sp = end.Subtract(start); return sp.Days + 1; } } }
标签:C#,DateTime,处理,int,时间,mouth,dt,public From: https://www.cnblogs.com/Lcsxx/p/16936095.html