zoukankan      html  css  js  c++  java
  • 呵呵,日期小小技巧

    Code
            //获取当前日期所在月份的最后一天
            public     DateTime GetLastDayOfMonth(DateTime dt)
            {
                
    if (dt.Month==1 || dt.Month==3 || dt.Month==5 || dt.Month==7 || dt.Month==8 || dt.Month==10 || dt.Month==12)
                    
    return new DateTime(dt.Year,dt.Month,31);
                
    else
                {
                    
    if (dt.Month==4 || dt.Month==6 || dt.Month==5 || dt.Month==9 || dt.Month==11)
                        
    return new DateTime(dt.Year,dt.Month,30);
                    
    else
                    {
                        DateTime leapyear;
                        
    try
                        {
                            leapyear  
    =new DateTime(dt.Year,dt.Month,29);
                        }
                        
    catch (Exception e)
                        {
                            leapyear
    =new DateTime(dt.Year,dt.Month,28);
                        }
                        
    return leapyear;
                        
                    }
                }
            }

    这个太落后了吧,

    最简单算法是,下个月的1号减一天就到了当前月份的最后一天

  • 相关阅读:
    C#使用xpath简单爬取网站的内容
    Python的安装以及编译器的安装
    解析二维码
    C#的历史及IDE总结
    我又回来了,这回是带着C++来的
    Python 基础知识
    template declarations(模板声明)中 class 和 typename 有什么不同?
    投影点坐标
    内存对齐代码解析
    互斥量和信号量的区别
  • 原文地址:https://www.cnblogs.com/panzhilei/p/1454665.html
Copyright © 2011-2022 走看看