Skip to content

Instantly share code, notes, and snippets.

@thejavalistener
Created November 22, 2013 14:38
Show Gist options
  • Save thejavalistener/7600849 to your computer and use it in GitHub Desktop.
Save thejavalistener/7600849 to your computer and use it in GitHub Desktop.
package com.thejavalistener.fechas;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class SumaDias
{
public static void main(String[] args)
{
// defino una fecha (2/octubre/1980)
int dia=2;
int mes=10;
int anio=1980;
// instancio un GregorianCalendar y le seteo la fecha
GregorianCalendar g=new GregorianCalendar(anio,mes-1,dia);
// le sumo 10 dias
int nDias = 10;
g.add(Calendar.DAY_OF_MONTH,nDias);
// obtengo el dia, mes y anio resultante
dia = g.get(Calendar.DAY_OF_MONTH);
mes = g.get(Calendar.MONTH)+1;
anio = g.get(Calendar.YEAR);
// muestro
String sFecha = dia+"/"+mes+"/"+anio;
System.out.println(sFecha);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment