获取一个星期时间段的具体日期

经常要需要得出某一日期是星期几,或者需要在一个星期段中获取数据
下面是实现方法,有3段程序,分别为"数据绑定"过程,"上一周"和"下一周"按钮
说明:当点击上一周,求出Session[StartDate]和Session[DueDate],然后根据这个时间段,来求数据.
//iWeek.ToString()为第几周
//dStartDate.Month.ToString()在一个星期段中开始月份
//dStartDate.Day.ToString()在一个星期段中开始日期
//dDueDate.Month.ToString()在一个星期段中结束月份
//dDueDate.Day.ToString()在一个星期段中结束日期
//Session[StartDate]和Session[DueDate]就是时间段了

1.数据绑定过程
ExpandedBlockStart.gif ContractedBlock.gif private   void  InitFormData() 
 
dot.gif {   
   System.Globalization.Calendar ce 
= new GregorianCalendar();
   
int iWeek = ce.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday);
   
int iDay = (int) DateTime.Now.DayOfWeek;  
    DateTime dStartDate 
= DateTime.Now.AddDays( -(iDay - 1));  
    DateTime dDueDate 
= DateTime.Now.AddDays( -(iDay - 1+ 6 );
   Session[
"StartDate"= dStartDate.ToShortDateString() + " 0:00:00";
   Session[
"DueDate"= dDueDate.ToShortDateString() + " 23:59:59";
}
2.上一周按钮事件
1 ExpandedBlockStart.gif ContractedBlock.gif private   void  btnPrevious_Click( object  sender, System.EventArgs e)   dot.gif
{
2InBlock.gif   System.Globalization.Calendar ce = new GregorianCalendar();  
3InBlock.gif DateTime dStartDate = DateTime.Parse(Session["StartDate"].ToString()).AddDays( - 7 );
4InBlock.gif   DateTime dDueDate = DateTime.Parse(Session["DueDate"].ToString()).AddDays( - 7 ); 
5InBlock.gif  Session["StartDate"= dStartDate.ToShortDateString() + " 0:00:00";
6InBlock.gif   Session["DueDate"= dDueDate.ToShortDateString() + " 23:59:59"
7InBlock.gif  int iWeek = ce.GetWeekOfYear(dStartDate, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday); 
8ExpandedBlockEnd.gif }
3.下一周按钮事件
1 None.gif private   void  btnNext_Click( object  sender, System.EventArgs e)  
2 ExpandedBlockStart.gifContractedBlock.gif dot.gif {   
3InBlock.gifSystem.Globalization.Calendar ce = new GregorianCalendar();
4InBlock.gif   DateTime dStartDate = DateTime.Parse(Session["StartDate"].ToString()).AddDays( 7 );
5InBlock.gif   DateTime dDueDate = DateTime.Parse(Session["DueDate"].ToString()).AddDays( 7 );  
6InBlock.gif Session["StartDate"= dStartDate.ToShortDateString() + " 0:00:00";  
      Session[
"DueDate"= dDueDate.ToShortDateString() + " 23:59:59";   
7InBlock.gifint iWeek = ce.GetWeekOfYear(dStartDate, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday);
8ExpandedBlockEnd.gif  }

转载于:https://www.cnblogs.com/zjy/archive/2006/08/17/479562.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值