Java Calendar

[java title=”CalendarExample.java” gutter=”true” highlight=”10″]
import java.util.*;

public class CalendarExample {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

/*
* Add a day to the Calendar Object using add function
*/

Calendar cal = Calendar.getInstance();

/*
* Prints out the full Calendar Object
*/

System.out.println(cal);

// Get the current day of the month – For example, 18th march 2012 would be 18
System.out.println( " day is " + cal.get(Calendar.DAY_OF_MONTH));

// Set the Calendar to tomorrow.
cal.add(Calendar.DAY_OF_MONTH,1);
System.out.println( " day is " + cal.get(Calendar.DAY_OF_MONTH));

// What would be the day, 1 year from now ?
System.out.println( "Today’s DAY is " + cal.get (Calendar.DAY_OF_WEEK));
cal.add(Calendar.YEAR , 1);
System.out.println("This day next year would be a " + cal.get (Calendar.DAY_OF_WEEK)  );
System.out.println(" And next year is " + cal.get(Calendar.YEAR));

}

}

[/java]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s