URGENTE - Intervalos entre datas

2 respostas
F

Alguém conheçe algum metodo que calcule o intervalo de dias entre duas datas?

2 Respostas

M

cara… eu ja fiz isso com GregorianCalendar… só não me pergunta como foi pq faz tempo hehehe

P
import java.util.*;

public class Teste{
	
	public static void main (String args[]){	
	  Date b = new Date(2004,04,04);
	  Date e = new Date(2004,04,10);
	 	Teste  teste = new Teste(b,e);
	
		System.out.println(String.valueOf(e)+" - "+String.valueOf(b)+" = " + String.valueOf(teste.intervalo()));
	}
	

	public Date begin;
	public Date end;
	
	public Teste(Date b, Date e){
		this.begin = b;
		this.end = e;		
	}
	
	public int intervalo(){
		Calendar calendar = Calendar.getInstance() ;
		calendar.setTime(begin);
		int b = calendar.get(Calendar.DAY_OF_YEAR);
		calendar.setTime(end);
		int e = calendar.get(Calendar.DAY_OF_YEAR);
		return e-b;
	}

}
Criado 30 de março de 2005
Ultima resposta 30 de mar. de 2005
Respostas 2
Participantes 3