最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
C#获取每个年,月,周的起始日期和结束日期的方法
时间:2022-06-25 07:51:52 编辑:袖梨 来源:一聚教程网
我们在写程序的时候往往要计算出年,月,周的开始日期和结束日期,在这里给出统一求解方法
| 代码如下 | 复制代码 |
/// /// 声明期间类型枚举 /// publicenumPeriod {Day, Week, Month, Year}; /// /// 获取指定期间的起止日期 /// /// 期间类型 /// 开始日期 /// 结束日期 publicstaticvoidGetPeriod(Period period,outDateTime beginDate,outDateTime endDate) { intyear = DateTime.Today.Year; intmonth = DateTime.Today.Month; switch(period) { casePeriod.Year://年 beginDate =newDateTime(year, 1, 1); endDate =newDateTime(year, 12, 31); break; casePeriod.Month://月 beginDate =newDateTime(year, month, 1); endDate = beginDate.AddMonths(1).AddDays(-1); break; casePeriod.Week://周 intweek = (int)DateTime.Today.DayOfWeek; if(week == 0) week = 7;//周日 beginDate = DateTime.Today.AddDays(-(week - 1)); endDate = beginDate.AddDays(6); break; default://日 beginDate = DateTime.Today; endDate = DateTime.Today; break; } } | |
相关文章
- 重生:新婚旧梦官网在哪下载 最新官方下载安装地址 07-22
- 重生:新婚旧梦何时出 公测上线时间预告 07-22
- 10子棋何时出 公测上线时间预告 07-22
- 《燕云十六声》浴血难度河伯打法及特点介绍 07-22
- 10子棋官网在哪下载 最新官方安装地址 07-22
- 10子棋好玩不 10子棋玩法简介 07-22