java 计算生日 剩余天数 (两个日期间隔天数)

 public Object decorate(Object columnValue, PageContext pageContext, MediaTypeEnum media) throws DecoratorException
    {
        Object obj = null;
        Date tt=new Date();
        if (columnValue!=null)
        {
         Date date = (Date) columnValue;//获取到  生日  日期         比如1999  6 25
         if(date.equals(""))
         {
          obj=null;
         }
         else
         {
          int temp = tt.getYear();
          date.setYear(temp);//转换为 2010  6 25
          

//设置  当前 日期  比如  2010 6  20
                Calendar fromCalendar = Calendar.getInstance();  
                fromCalendar.setTime(tt);  
                fromCalendar.set(Calendar.HOUR_OF_DAY, 0);  
                fromCalendar.set(Calendar.MINUTE, 0);  
                fromCalendar.set(Calendar.SECOND, 0);  
                fromCalendar.set(Calendar.MILLISECOND, 0);   
   //设置  生日  日期         比如 2010 6 25
                Calendar toCalendar = Calendar.getInstance();  
                toCalendar.setTime(date);  
                toCalendar.set(Calendar.HOUR_OF_DAY, 0);  
                toCalendar.set(Calendar.MINUTE, 0);  
                toCalendar.set(Calendar.SECOND, 0);  
                toCalendar.set(Calendar.MILLISECOND, 0);   
       //结果将会 两个日期间隔天数 是5天   
                Long tempString = (toCalendar.getTime().getTime() - fromCalendar.getTime().getTime()) / (1000 * 60 * 60 * 24);
                obj=String.valueOf(tempString);
         }
        }
       
        return obj;
    }

你可能感兴趣的:(java 计算生日 剩余天数 (两个日期间隔天数))