Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/10/2012, 17:11
redadicto
 
Fecha de Ingreso: octubre-2012
Mensajes: 5
Antigüedad: 11 años, 6 meses
Puntos: 0
Duda con funcion java para manipular fechas....?

Hola a toda la comunidad....

Hice una funcion que me pasa del formato BD (2012-20-20) a 20/20/2012....

La funcion me da vuelta la fecha, poniendole las barras y demas...

Pero le suma un mes mas al dado....

La funcion es la siguiente.....


Código PHP:
Ver original
  1. public String reversefecha(String id_fecha){
  2.        
  3.         String[] array_fechasol = id_fecha.split("-");
  4.        
  5.         int day = Integer.parseInt(array_fechasol[2]);
  6.         int month = Integer.parseInt(array_fechasol[1]);
  7.         int year = Integer.parseInt(array_fechasol[0]);
  8.        
  9.         Calendar cal = Calendar.getInstance();
  10.        
  11.         cal.clear();
  12.        
  13.         cal.set(Calendar.YEAR, year);
  14.         cal.set(Calendar.MONTH, month);
  15.         cal.set(Calendar.DATE, day);
  16.        
  17.         java.util.Date utilDate = cal.getTime();
  18.        
  19.         //String format= "dd/MM/yyyy";
  20.        
  21.         SimpleDateFormat sdf= new SimpleDateFormat("dd/MM/yyyy");
  22.        
  23.         String horaFormateada = sdf.format(utilDate);
  24.        
  25.         return horaFormateada;
  26.        
  27.    
  28.     }

Les parece que esta hecha bien la funcion o tendria que hacerla de otra manera...?

Espero su ayuda....

Muchas Gracias desde ya...

RedAdicto