曾经爱晚人








永远自由的心

[转] c# 时间操作

一、取某月的最后一天

一、取某月的最后一天
法一、使用算出该月多少天,年
++加上多少天即得,举例取今天这个月的最后一天

private void GetLastDateForMonth(DateTime DtStart,out DateTime DtEnd)
  
{
   
int Dtyear,DtMonth;

   DtStart 
= DateTime.Now;
   Dtyear  
= DtStart.Year;
   DtMonth 
= DtStart.Month;

   
int MonthCount = DateTime.DaysInMonth(Dtyear,DtMonth);
   DtEnd 
= Convert.ToDateTime(Dtyear.ToString()+"-"+DtMonth.ToString()+"-"+MonthCount);

  }


法二、取出下月的第一天减去一天便是这个的最后一天

private void GetLastDateForMonth(DateTime DtStart,out DateTime DtEnd)
  
{
   
int Dtyear,DtMonth;

   DtStart 
= DateTime.Now.AddMonths(1);
   Dtyear  
= DtStart.Year;
   DtMonth 
= DtStart.Month;
   
   DtEnd 
= Convert.ToDateTime(Dtyear.ToString()+"-"+DtMonth.ToString()+"-"+"1").AddDays(-1);

  }




法一、使用算出该月多少天,年++加上多少天即得,举例取今天这个月的最后一天

法二、取出下月的第一天减去一天便是这个的最后一天

posted on 2006-07-19 20:58  e旋风  阅读(1165)  评论(0编辑  收藏  举报

导航