Java日历getInstance方法


Java日历getInstance方法

package com.codingdict;

import java.util.*;

public class CalendarDemo {
   public static void main(String[] args) {

      // create a calendar
      TimeZone tz1 = TimeZone.getTimeZone("GMT");
      Calendar cal1 = Calendar.getInstance(tz1);

      // create a second calendar with different timezone
      TimeZone tz2 = TimeZone.getTimeZone("EST");
      Calendar cal2 = Calendar.getInstance(tz2);

      // display time zone for both calendars
      System.out.println("GMT: " + cal1.getTimeZone().getDisplayName());
      System.out.println("EST: " + cal2.getTimeZone().getDisplayName());
   }
}