• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
张继东
看铁蹄铮铮,踏遍万里河山。磨不破,打不烂。
   首页    新随笔    联系   管理    订阅  订阅

c#求某月的总天数

1. 凡公元的年数被4整除的是『闰年』,如1988、1992、1996…...;但
2. 在400年之中有3年是例外,這3年的公元年數是100的倍数。如1700、1800、1900不是『闰年』。但
3. 被400整除的又是『闰年』;如1600、2000年。
c#手动写法

    private int conday(int intYear,int intMonth)
        {
            
int dayMax=0;
            
int year = Convert.ToInt32(intYear);
            
if (intMonth == 2)
            {
                dayMax 
= (( year % 4 ==0) && ((year % 100) !=0 )) ||(year % 400 == 0) ? 29 : 28;
            }
            
else
            {
                
if (intMonth ==1||intMonth ==3||intMonth ==5||intMonth ==7||intMonth ==8||intMonth ==10||intMonth ==12)
                {
                    dayMax
= 31; 
                }
                
else 
                {
                    dayMax 
= 30;  
                }
            }
            
return dayMax;
        }


其实.net早已经提供了此方法例如:

System.DateTime.DaysInMonth(1996, 2);


另外

System.DateTime.IsLeapYear(1996);

判断是否为闰年

 

posted @ 2005-11-02 10:15  简单生活  阅读(1595)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3