Code example for GregorianCalendar

Methods: getTime, set, setTime

0
        if ( end == null )
        { 
            throw new IllegalArgumentException( "end ne peut etre null" );
        } 
 
        GregorianCalendar calendarStart = new GregorianCalendar();
        calendarStart.setTime( start );
        // forcage a 12 pour pb passage hiver/ete 
        calendarStart.set( Calendar.HOUR_OF_DAY, 12 );
        calendarStart.set( Calendar.MINUTE, 0 );
        calendarStart.set( Calendar.SECOND, 0 );
        calendarStart.set( Calendar.MILLISECOND, 0 );
        //calendarStart.setLenient( false ); 
 
        GregorianCalendar calendarEnd = new GregorianCalendar();
        calendarEnd.setTime( end );
        // forcage a 12 pour pb passage hiver/ete 
        calendarEnd.set( Calendar.HOUR_OF_DAY, 12 );
        calendarEnd.set( Calendar.MINUTE, 0 );
        calendarEnd.set( Calendar.SECOND, 0 );
        calendarEnd.set( Calendar.MILLISECOND, 0 );
        //calendarEnd.setLenient( false ); 
        if ( calendarEnd.getTime().compareTo( calendarStart.getTime() ) == 0 )
        { 
            return 0; 
        } 
 
        double diff = ( (double) calendarEnd.getTime().getTime() - (double) calendarStart.getTime().getTime() );
        double div = diff / MS_DAY_MULTIPLIER;
 
        // Pour gestion des changement d'heure hiver/ete (on a pas de petrol mais on a des idees) 
        return (int) Math.round( div );
    }