• [转] 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);

      }




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

    法二、取出下月的第一天减去一天便是这个的最后一天
  • 相关阅读:
    线程池类型场景和问题
    react Antdesign Select添加全选功能
    API与ESB 、ServiceMesh、微服务究竟关系如何?
    RabbitMQ四种Exchange类型
    RabbitMq安装
    kafka 部署
    共享文件夹重启后每次都要输入密码
    algorithm 12 partial_sort_copy
    algorithm 11 nth_element
    algorithm 11 none_of
  • 原文地址:https://www.cnblogs.com/xiang/p/454957.html
Copyright © 2020-2023  润新知