jdk/src/share/classes/java/util/TimeZone.java
changeset 15658 55b829ca2334
parent 15260 7af2d7a87806
child 16005 b480157c22fe
equal deleted inserted replaced
15657:c588664d547e 15658:55b829ca2334
    40 
    40 
    41 import java.io.Serializable;
    41 import java.io.Serializable;
    42 import java.lang.ref.SoftReference;
    42 import java.lang.ref.SoftReference;
    43 import java.security.AccessController;
    43 import java.security.AccessController;
    44 import java.security.PrivilegedAction;
    44 import java.security.PrivilegedAction;
       
    45 import java.time.ZoneId;
    45 import java.util.concurrent.ConcurrentHashMap;
    46 import java.util.concurrent.ConcurrentHashMap;
    46 import sun.misc.JavaAWTAccess;
    47 import sun.misc.JavaAWTAccess;
    47 import sun.misc.SharedSecrets;
    48 import sun.misc.SharedSecrets;
    48 import sun.security.action.GetPropertyAction;
    49 import sun.security.action.GetPropertyAction;
    49 import sun.util.calendar.ZoneInfo;
    50 import sun.util.calendar.ZoneInfo;
   528      */
   529      */
   529     public static synchronized TimeZone getTimeZone(String ID) {
   530     public static synchronized TimeZone getTimeZone(String ID) {
   530         return getTimeZone(ID, true);
   531         return getTimeZone(ID, true);
   531     }
   532     }
   532 
   533 
       
   534     /**
       
   535      * Gets the {@code TimeZone} for the given {@code zoneId}.
       
   536      *
       
   537      * @param zoneid a {@link ZoneId} from which the time zone ID is obtained
       
   538      * @return the specified {@code TimeZone}, or the GMT zone if the given ID
       
   539      *         cannot be understood.
       
   540      * @throws NullPointerException if {@code zoneId} is {@code null}
       
   541      * @since 1.8
       
   542      */
       
   543     public static TimeZone getTimeZone(ZoneId zoneId) {
       
   544         String tzid = zoneId.getId(); // throws an NPE if null
       
   545         char c = tzid.charAt(0);
       
   546         if (c == '+' || c == '-') {
       
   547             tzid = "GMT" + tzid;
       
   548         } else if (c == 'Z' && tzid.length() == 1) {
       
   549             tzid = "UTC";
       
   550         }
       
   551         return getTimeZone(tzid, true);
       
   552     }
       
   553 
       
   554     /**
       
   555      * Converts this {@code TimeZone} object to a {@code ZoneId}.
       
   556      *
       
   557      * @return a {@code ZoneId} representing the same time zone as this
       
   558      *         {@code TimeZone}
       
   559      * @since 1.8
       
   560      */
       
   561     public ZoneId toZoneId() {
       
   562         return ZoneId.of(getID(), ZoneId.OLD_IDS_POST_2005);
       
   563     }
       
   564 
   533     private static TimeZone getTimeZone(String ID, boolean fallback) {
   565     private static TimeZone getTimeZone(String ID, boolean fallback) {
   534         TimeZone tz = ZoneInfo.getTimeZone(ID);
   566         TimeZone tz = ZoneInfo.getTimeZone(ID);
   535         if (tz == null) {
   567         if (tz == null) {
   536             tz = parseCustomTimeZone(ID);
   568             tz = parseCustomTimeZone(ID);
   537             if (tz == null && fallback) {
   569             if (tz == null && fallback) {