Problema com Calendar

2 respostas
luistiagos

Neste codigo:

Calendar c = Calendar.getInstance();
		DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
		Date d = df.parse("12/10/2008");
		c.setTime(d);
		
		System.out.println(c.get(Calendar.MONTH));

ele ne retorna o mes 9 invez do mes 10… pq? como faço para que ele me retorne a data com o mes correto?

2 Respostas

adriano.ferranti

MONTH
public static final int MONTH
Field number for get and set indicating the month. This is a calendar-specific value. The first month of the year is JANUARY which is 0; the last depends on the number of months in a year.

Fonte:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html#MONTH

felipealbuquerque

O MONTH retorna um número zero-based para o mês. Por exemplo, para Janeiro retorna 0, para Fevereiro, retorna 1, e assim sucessivamente.

Criado 11 de março de 2008
Ultima resposta 11 de mar. de 2008
Respostas 2
Participantes 3