Created
November 22, 2013 14:38
-
-
Save thejavalistener/7600849 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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