写了一个J2ME里操作日期的类,只有一个方法,就是给日期增加一个增量,然后算出日期

做的时候发现一个怪问题,在索爱模拟器T610和T630上运行正常的程序,通过蓝牙发到T628上就运行错误,奇怪~~~~谁能给我解释一下呀~~~

操作日期的类如下:
/*
 * Created on 2005-1-14
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.booolee;

import java.util.*;

/**
 * @author libo
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class BOBO_Date {
 /**
  * 对日期进行增/减量操作
  * @param d  日期
  * @param days 增量天数
  * @return  Date
  */
 public Date add(Date d,int days){
  int Year,Month,Month2,Month_r,Day,Day2,Day_r,i;
  boolean rYear;
  int DayOfMonths[]={31,28,31,30,31,30,31,31,30,31,30,31};
  Calendar cal;
  cal=Calendar.getInstance();
  cal.setTime(d);
  Year=cal.get(cal.YEAR);
  Month=cal.get(cal.MONTH);
  Day=cal.get(cal.DAY_OF_MONTH);
  
  Day2=Day+days;
  
  //判断是否为闰年
  if (( Year % 4 == 0 && Year % 100 != 0)||Year % 400 == 0) {
   rYear=true;
  }else{
   rYear=false;
  }
  
  //如果是闰年,2月份就是29天否则是28天
  if (rYear){
   DayOfMonths[1]=29;
  }else{
   DayOfMonths[1]=28;
  }
  
  //跨度为几个月,请求出结果月
  i=0;
  while (true){
   if ((Month+i)>11){
    Month=1;
    i=0;
    Year++;
   }
   Day_r=Day2;
   Day2=Day2-DayOfMonths[Month+i];
   if (Day2<0){
    Month_r=Month+i+1;
    break;
   }else{
    i++;
   }
  }
  
  cal.set(cal.YEAR,Year);
  cal.set(cal.MONTH,Month);
  cal.set(cal.DAY_OF_MONTH,Day_r);
  
  return cal.getTime();
 }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值