Calendar Manipulation for I18N (Internationalization) : Calendar « I18N « Java






Calendar Manipulation for I18N (Internationalization)

Calendar Manipulation for I18N (Internationalization)
 
import java.text.*;
import java.util.*;

public class CalendarManipulation {
  public static void main(String s[]) {
    Calendar cal = Calendar.getInstance();
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL,
                                                   DateFormat.MEDIUM);
    // print out the current date and time
    System.out.println(df.format(cal.getTime()));

    // add 8 days to the current date and print out the date and time
    cal.add(Calendar.DATE, 8);
    System.out.println(df.format(cal.getTime()));

    // subtract 4 hours from the time and print out the date and time
    cal.add(Calendar.HOUR, -4);
    System.out.println(df.format(cal.getTime()));

    // add 12 hours to the current time and print out the date and time
    cal.add(Calendar.AM_PM, 1);
    System.out.println(df.format(cal.getTime()));

    // add another 12 hours and print out the date and time
    cal.add(Calendar.AM_PM, 1);
    System.out.println(df.format(cal.getTime()));
  }
}           
         
  








Related examples in the same category

1.Locales for CalendarLocales for Calendar
2.Create an instance using Japan's time zone and set it with the local UTC
3.Get the foreign time
4.Given a time of 10am in Japan, get the local time