The Calendar Class : Date « Utility Classes « SCJP






import java.util.Calendar;
import java.util.Date;

public class MainClass {
  public static void main(String[] args) {
    Date d1 = new Date(1000000000000L);
    System.out.println("1st date " + d1.toString());

    Calendar c = Calendar.getInstance();
    c.setTime(d1);

    if (Calendar.SUNDAY == c.getFirstDayOfWeek()) {
      System.out.println("Sunday is the first day of the week");
    }
    System.out.println("trillionth milli day of week is " + c.get(Calendar.DAY_OF_WEEK));

    c.add(Calendar.MONTH, 1);
    Date d2 = c.getTime();
    System.out.println("new date " + d2.toString());
  }
}
1st date Sat Sep 08 18:46:40 PDT 2001
Sunday is the first day of the week
trillionth milli day of week is 7
new date Mon Oct 08 18:46:40 PDT 2001








8.26.Date
8.26.1.How Date, GregorianCalendar, and TimeZone objects are created and how to use their methods to access date/time information.
8.26.2.Get the current date and time.
8.26.3.Date and time calculations, and format date in different locales with different date styles.
8.26.4.Find out how long it took for a trillion milliseconds to pass, starting at January 1, 1970
8.26.5.The Calendar Class
8.26.6.The DateFormat Class
8.26.7.DateFormat.format(), DateFormat.parse()