how would i make a program that prints out the date after a number of days from June 1st,2013? Any help is appreciated
Example: if 45 is entered it should output July 16,2013
Im using ReadyToPrgram btw if this matters
how would i make a program that prints out the date after a number of days from June 1st,2013? Any help is appreciated
Example: if 45 is entered it should output July 16,2013
Im using ReadyToPrgram btw if this matters
Here is one nice tutorial
SimpleDateFormat sdf = new SimpleDateFormat("yyyy MMM dd");
Calendar calendar = new GregorianCalendar(2013,7,1);
System.out.println("Date : " + sdf.format(calendar.getTime()));
//add one month
calendar.add(Calendar.MONTH, 1);
System.out.println("Date : " + sdf.format(calendar.getTime()));
This will increase any date by exactly one
String untildate="2013-07-16";//can take any date in current format
SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
Calendar cal = Calendar.getInstance();
cal.setTime( dateFormat.parse(untildate));
cal.add( Calendar.DATE, 1 );
String convertedDate=dateFormat.format(cal.getTime());
System.out.println("Date increase by one.."+convertedDate);
You can use the java.util.Date and java.util.Calendar classes bundled with Java. But they are notoriously troublesome.
For years now the Joda-Time third-party open-source library has been a popular substitute.
If you are sure you want just the date alone, without time and time zones use Joda-Time’s LocalDate
class. Example…
LocalDate localDate = new LocalDate( 2013, 6, 1 ).plusDays( 45 );
System.out.println( "localDate " + localDate );
Search around StackOverflow.com. These basic date and time questions have already been asked and answered.