判断闰年和怎么判断年月日的正确

package cn.true123.cn;
public class Utils{
 /**
  *
  */
 public static int check_year(String year) {
  int thisyear = 0;
  if (year == null || year == "") {
   return -1;
  } else if (year.length() < 4) {
   return -2;
  } else if (year.length() == 4) {
   thisyear = Integer.parseInt(year);
  } else if (year.length() == 8) {
   thisyear = Integer.parseInt(year.substring(0, 4));
  }
  if (thisyear % 400 == 0 || (thisyear % 4 == 0 & thisyear % 100 != 0)) {
   return 0;
  }
  return 0;
 }

 public static boolean check_date(String year) {
  int thisyear = 0;
  int thismonth = 0;
  int thisday = 0;
  if (year == null || year == "") {
   return false;
  } else if (year.length() < 8) {
   return false;
  }
  thisyear = Integer.parseInt(year.substring(0, 4));
  thismonth = Integer.parseInt(year.substring(4, 6));
  thisday = Integer.parseInt(year.substring(6, 8));
  if (thismonth < 1 || thismonth > 12) {
   return false;
  } else if (thismonth == 1 || thismonth == 3 || thismonth == 5
    || thismonth == 7 || thismonth == 8 || thismonth == 10
    || thismonth == 12) {
   if (thisday < 1 || thisday > 31) {
    return false;
   }
  } else {
   if (thisday < 1 || thisday > 30) {
    return false;
   }
  }
  if (thismonth == 2) {
   if (check_year(String.valueOf(thisyear)) == 0) {
    if (thisday > 29) {
     return false;
    }
   } else {
    if (thisday > 28) {
     return false;
    }
   }
  }
  return true;
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值