Mega Code Archive

 
Categories / Java / 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()));   } }