zoukankan      html  css  js  c++  java
  • [转] 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);

      }




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

    法二、取出下月的第一天减去一天便是这个的最后一天
  • 相关阅读:
    python之连接oracle数据库
    从一副牌中随机抽一张牌
    判断一个点是否在圆内
    判断每个月有多少天
    猜数字游戏
    求一元二次方程的2个跟
    Servlet细节处理
    Servlet
    Http协议
    Struts2(2)
  • 原文地址:https://www.cnblogs.com/xiang/p/454957.html
Copyright © 2011-2022 走看看