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号减一天就到了当前月份的最后一天

  • 相关阅读:
    mybatis判断字符串是否相等采坑记
    acm时加快cin和cout
    算法竞赛中的无穷大和无穷小
    Electron 安装、运行和项目搭建
    在线更新ubuntu 服务器补丁
    Cannot find module 'webpack/lib/RequestShortener'
    npm install --registry=https://registry.npm.taobao.org
    next InitializeSecurityContext failed
    npm安装typescript
    xmall
  • 原文地址:https://www.cnblogs.com/panzhilei/p/1454665.html
Copyright © 2011-2022 走看看