Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Does anyone know a good date parser for different languages/locales. The built-in parser of Java (SimpleDateFormat) is very strict. It should complete missing parts with the current date. For example if I do not enter the year (only day and month) then the current year should be used. if the year is 08 then it should not parse 0008 because the current year pattern has 4 digits. Edit: I ...
Java & Oracle both have a timestamp type called Date. Developers tend to manipulate these as if they were calendar dates, which I've seen cause nasty one-off bugs. For a basic date quantity you can simply chop off the time portion upon input, i.e., reduce the precision. But if you do that with a date range, (e.g.: 9/29-9/30), the difference between these two values is 1 day, rather than 2...
I am running a Tomcat application, and I need to display some time values. Unfortunately, the time is coming up an hour off. I looked into it and discovered that my default TimeZone is being set to: sun.util.calendar.ZoneInfo[id="GMT-08:00", offset=-28800000,dstSavings=0,useDaylight=false, transitions=0,lastRule=null] Rather than the Pacific time zone. This is further indicated wh...
We have a simple utility app that reads all the time zone data used in a JRE and displays it all in a simple table. We need to use an older version of the JRE (6_24) for an upcoming product release (due to other issues apparently), but we also need to include newer time zone updates in that release (that would otherwise be included in, say, 6_29). We're already packaging a private JRE that will...
While doing some research on timezones I found this interesting post on the GeoNames forum: rawOffset gives the fixed timezone. dstOffset gives the civil time offset from GMT on July 1st gmtOffset gives the civil time offset from GMT on January 1st On the southern hemisphere, for example for Chile (http://ws.geonames.org/timezone?lat=-33.46912&lng=-70.641997) we have the followi...
I need to generate a list of timezones to display for a user. We'd like to narrow the list down depending on the user's Locale. If the user has a locale of 'en_US', he probably doesn't care to see 'Asia/Ashkhabad' in the list. Is this doable?
java.util.TimeZone.getTimeZone(id) is a method to obtain a timezone based on an id. While I was using the class I opened it with a decompiler and noticed that it is synchronized. And since it is static, this means that no two threads can invoke the method at the same time. This could be very painful if multiple threads (in a web application for example) are often getting timezones. Why does it ...
I have my app hosted in a London Server. I am in Madrid, Spain. So the timezone is -2 hours. How can I obtain the current date / time with my time zone. Date curr_date = new Date(System.currentTimeMillis()); e.g. Date curr_date = new Date(System.currentTimeMillis("MAD_TIMEZONE")); With JODA DateTimeZone zone = DateTimeZone.forID("Europe/Madrid"); DateTime dt = new DateTime(zone); int ...
I'm having weird problem with java TimeZone.. Calling TimeZone.getDefault() gives my local time zone, which has an ID "GMT+02:00". Funny thing is that this ID doesn't appear in a list provided by TimeZone.getAvailableIDs(). Apparently my zone appears to be "Etc/GMT+2". I'm trying to populate a combo with time zones, but it's impossible to put a selection because GMT+02:00 is not in the list.....
I will be retrieving values from the range -12 to +12 & I need to convert it to a specific timezone format string. e.g. -3 becomes -03:00 0 becomes Z 4 becomes +04:00 Is there any readymade utility that I've overlooked that does the same thing in JDK6 ? Thanks
I know I can feed VM arguments as follows -Duser.timezone="Australia/Sydney" Is there a programmatic way to do the equivalent? I would like the setting to be applied across the entire virtual machine.
By default, what time zone does method java.util.Date.toString() display? Since a Java Date stores a given date in UTC and doesn't contain any explicit time zone, does Date.toString() simply display the default time zone for the host, or TimeZone.getDefault()?
I a newbie to java and hence haven't been able figure this out since quite some time. I am using Windows XP and the machine is set to TimeZone: Eastern Time (US & Canada). I have a Java application, which takes the current system time and timezone info and writes a string like: 20101012 15:56:00 EST, to a file. The last piece of Date above, i.e.: the timezone, changes from EST to EDT as...
I build a Java TimeZone object using the TimeZone String like GMT-8,GMT,PST,EST etc. This did not consider whether the timezone is daylight saving enabled or not.Now there is a requirement to include this check and instead of giving the input as PDT or EDT the daylight saving is given as a seperate flag.I am not sure whether TimeZone has a direct method to change the dayLight saving property of...
I want to read the tzdata files (TimeZone) to convert a sourcetime in a targettime. I have downloaded the tzdata files, has anybody an example for me to read the tzdata file out?
Hi I am looking to set the timezone for San Antonio, Texas.Can some please tell me how do i set the same in my Java code. I want it in the format somewhat similar to America/New York Currently I am using TimeZone.getTimeZone("America/Denver") But "America/Denver" doesn't seem to be the right timezone for San Antonio, Texas
How can I get the current local wall clock time (in number of millis since 1 Jan 1970) in London? Since my application can run on a server in any location, I think I need to use a TimeZone of "Europe/London". I also need to take Daylight Savings into account i.e. the application should add an hour during the "summer". I would prefer to use the standard java.util libraries. Is this correct? T...
While trying to transform the date format I get an exception:unparseable date and don't know how to fix this problem. I am receiving a string which represents an event date and would like to display this date in different format in GUI. What I was trying to do is the following: private String modifyDateLayout(String inputDate){ try { //inputDate = "2010-01-04 01:32:27 UT...
I want to convert Strings like "20000603163334 GST" or "20000603163334 -0300" to UTC time. The problem is that time zones in my strings can be 'general time zones', I mean they can be strings as CET, GST etc. etc. And I don't know how to convert these ones. Because of these string time zones I can not use Joda Time's DateTimeFormat.forPattern("yyyyMMddhhmmss z").withZone(DateTimeZone.UTC);, b...
My server sends me time zones of the format "America/Los Angeles". On the client, I have a time that I need to display in that time zone. The answer will be "PST" or "PDT", depending on daylight savings at the given time. How do I do that conversion? I'm on Java ME (Blackberry 4.7, to be accurate), so I can't use Joda Time. I will need to make this calculation rapidly for a lot of dates (but ...
Does anyone know a webservice that converts a timezone string to the corresponding GMT Offset? Meaning I like to send a HTTP request like this: http://servcer.com/getgmtoffset?timezone=Europe/Zurich and get "+1" returned. Why external service? I'm writing a google apps script, where the API does not have such conversion options and I prefer not to update the conversion table myself, when c...
  /*
   * Copyright 1996-2005 Sun Microsystems, Inc.  All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Sun designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Sun in the LICENSE file that accompanied this code.
  *
  * This code is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * version 2 for more details (a copy is included in the LICENSE file that
  * accompanied this code).
  *
  * You should have received a copy of the GNU General Public License version
  * 2 along with this work; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  * CA 95054 USA or visit www.sun.com if you need additional information or
  * have any questions.
  */
 
 /*
  * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
  * (C) Copyright IBM Corp. 1996 - All Rights Reserved
  *
  *   The original version of this source code and documentation is copyrighted
  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
  * materials are provided under terms of a License Agreement between Taligent
  * and Sun. This technology is protected by multiple US and International
  * patents. This notice and attribution to Taligent may not be removed.
  *   Taligent is a registered trademark of Taligent, Inc.
  *
  */
 
 package java.util;
 
TimeZone represents a time zone offset, and also figures out daylight savings.

Typically, you get a TimeZone using getDefault which creates a TimeZone based on the time zone where the program is running. For example, for a program running in Japan, getDefault creates a TimeZone object based on Japanese Standard Time.

You can also get a TimeZone using getTimeZone along with a time zone ID. For instance, the time zone ID for the U.S. Pacific Time zone is "America/Los_Angeles". So, you can get a U.S. Pacific Time TimeZone object with:

 TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
 
You can use the getAvailableIDs method to iterate through all the supported time zone IDs. You can then choose a supported ID to get a TimeZone. If the time zone you want is not represented by one of the supported IDs, then a custom time zone ID can be specified to produce a TimeZone. The syntax of a custom time zone ID is:
 CustomID:
         GMT Sign Hours : Minutes
         GMT Sign Hours Minutes
         GMT Sign Hours
 Sign: one of
         + -
 Hours:
         Digit
         Digit Digit
 Minutes:
         Digit Digit
 Digit: one of
         0 1 2 3 4 5 6 7 8 9
 
Hours must be between 0 to 23 and Minutes must be between 00 to 59. For example, "GMT+10" and "GMT+0010" mean ten hours and ten minutes ahead of GMT, respectively.

The format is locale independent and digits must be taken from the Basic Latin block of the Unicode standard. No daylight saving time transition schedule can be specified with a custom time zone ID. If the specified string doesn't match the syntax, "GMT" is used.

When creating a TimeZone, the specified custom time zone ID is normalized in the following syntax:

 NormalizedCustomID:
         GMT Sign TwoDigitHours : Minutes
 Sign: one of
         + -
 TwoDigitHours:
         Digit Digit
 Minutes:
         Digit Digit
 Digit: one of
         0 1 2 3 4 5 6 7 8 9
 
For example, TimeZone.getTimeZone("GMT-8").getID() returns "GMT-08:00".

Three-letter time zone IDs

For compatibility with JDK 1.1.x, some other three-letter time zone IDs (such as "PST", "CTT", "AST") are also supported. However, their use is deprecated because the same abbreviation is often used for multiple time zones (for example, "CST" could be U.S. "Central Standard Time" and "China Standard Time"), and the Java platform can then only recognize one of them.

Author(s):
Mark Davis, David Goldsmith, Chen-Lieh Huang, Alan Liu
Since:
JDK1.1
See also:
Calendar
GregorianCalendar
SimpleTimeZone
abstract public class TimeZone implements SerializableCloneable {
    
Sole constructor. (For invocation by subclass constructors, typically implicit.)
    public TimeZone() {
    }

    
A style specifier for getDisplayName() indicating a short name, such as "PST."

Since:
1.2
See also:
LONG
    public static final int SHORT = 0;

    
A style specifier for getDisplayName() indicating a long name, such as "Pacific Standard Time."

Since:
1.2
See also:
SHORT
    public static final int LONG  = 1;
    // Constants used internally; unit is milliseconds
    private static final int ONE_MINUTE = 60*1000;
    private static final int ONE_HOUR   = 60*;
    private static final int ONE_DAY    = 24*;

    
Cache to hold the SimpleDateFormat objects for a Locale.
    private static Hashtable cachedLocaleData = new Hashtable(3);
    // Proclaim serialization compatibility with JDK 1.1
    static final long serialVersionUID = 3581463369166924961L;

    
Gets the time zone offset, for current date, modified in case of daylight savings. This is the offset to add to UTC to get local time.

This method returns a historically correct offset if an underlying TimeZone implementation subclass supports historical Daylight Saving Time schedule and GMT offset changes.

Parameters:
era the era of the given date.
year the year in the given date.
month the month in the given date. Month is 0-based. e.g., 0 for January.
day the day-in-month of the given date.
dayOfWeek the day-of-week of the given date.
milliseconds the milliseconds in day in standard local time.
Returns:
the offset in milliseconds to add to GMT to get local time.
See also:
Calendar.ZONE_OFFSET
Calendar.DST_OFFSET
    public abstract int getOffset(int eraint yearint monthint day,
                                  int dayOfWeekint milliseconds);

    
Returns the offset of this time zone from UTC at the specified date. If Daylight Saving Time is in effect at the specified date, the offset value is adjusted with the amount of daylight saving.

This method returns a historically correct offset value if an underlying TimeZone implementation subclass supports historical Daylight Saving Time schedule and GMT offset changes.

Parameters:
date the date represented in milliseconds since January 1, 1970 00:00:00 GMT
Returns:
the amount of time in milliseconds to add to UTC to get local time.
Since:
1.4
See also:
Calendar.ZONE_OFFSET
Calendar.DST_OFFSET
    public int getOffset(long date) {
        if (inDaylightTime(new Date(date))) {
            return getRawOffset() + getDSTSavings();
        }
        return getRawOffset();
    }

    
Gets the raw GMT offset and the amount of daylight saving of this time zone at the given time.

Parameters:
date the milliseconds (since January 1, 1970, 00:00:00.000 GMT) at which the time zone offset and daylight saving amount are found
offset an array of int where the raw GMT offset (offset[0]) and daylight saving amount (offset[1]) are stored, or null if those values are not needed. The method assumes that the length of the given array is two or larger.
Returns:
the total amount of the raw GMT offset and daylight saving at the specified date.
See also:
Calendar.ZONE_OFFSET
Calendar.DST_OFFSET
    int getOffsets(long dateint[] offsets) {
        int rawoffset = getRawOffset();
        int dstoffset = 0;
        if (inDaylightTime(new Date(date))) {
            dstoffset = getDSTSavings();
        }
        if (offsets != null) {
            offsets[0] = rawoffset;
            offsets[1] = dstoffset;
        }
        return rawoffset + dstoffset;
    }

    
Sets the base time zone offset to GMT. This is the offset to add to UTC to get local time.

If an underlying TimeZone implementation subclass supports historical GMT offset changes, the specified GMT offset is set as the latest GMT offset and the difference from the known latest GMT offset value is used to adjust all historical GMT offset values.

Parameters:
offsetMillis the given base time zone offset to GMT.
    abstract public void setRawOffset(int offsetMillis);

    
Returns the amount of time in milliseconds to add to UTC to get standard time in this time zone. Because this value is not affected by daylight saving time, it is called raw offset.

If an underlying TimeZone implementation subclass supports historical GMT offset changes, the method returns the raw offset value of the current date. In Honolulu, for example, its raw offset changed from GMT-10:30 to GMT-10:00 in 1947, and this method always returns -36000000 milliseconds (i.e., -10 hours).

Returns:
the amount of raw offset time in milliseconds to add to UTC.
See also:
Calendar.ZONE_OFFSET
    public abstract int getRawOffset();

    
Gets the ID of this time zone.

Returns:
the ID of this time zone.
    public String getID()
    {
        return ;
    }

    
Sets the time zone ID. This does not change any other data in the time zone object.

Parameters:
ID the new time zone ID.
    public void setID(String ID)
    {
        if (ID == null) {
            throw new NullPointerException();
        }
        this. = ID;
    }

    
Returns a name of this time zone suitable for presentation to the user in the default locale. This method returns the long name, not including daylight savings. If the display name is not available for the locale, then this method returns a string in the normalized custom ID format.

Returns:
the human-readable name of this time zone in the default locale.
Since:
1.2
    public final String getDisplayName() {
        return getDisplayName(false, Locale.getDefault());
    }

    
Returns a name of this time zone suitable for presentation to the user in the specified locale. This method returns the long name, not including daylight savings. If the display name is not available for the locale, then this method returns a string in the normalized custom ID format.

Parameters:
locale the locale in which to supply the display name.
Returns:
the human-readable name of this time zone in the given locale.
Since:
1.2
    public final String getDisplayName(Locale locale) {
        return getDisplayName(falselocale);
    }

    
Returns a name of this time zone suitable for presentation to the user in the default locale. If the display name is not available for the locale, then this method returns a string in the normalized custom ID format.

Parameters:
daylight if true, return the daylight savings name.
style either LONG or SHORT
Returns:
the human-readable name of this time zone in the default locale.
Since:
1.2
    public final String getDisplayName(boolean daylightint style) {
        return getDisplayName(daylightstyle, Locale.getDefault());
    }

    
Returns a name of this time zone suitable for presentation to the user in the specified locale. If the display name is not available for the locale, then this method returns a string in the normalized custom ID format.

Parameters:
daylight if true, return the daylight savings name.
style either LONG or SHORT
locale the locale in which to supply the display name.
Returns:
the human-readable name of this time zone in the given locale.
Throws:
java.lang.IllegalArgumentException style is invalid.
Since:
1.2
    public String getDisplayName(boolean daylightint styleLocale locale) {
        if (style !=  && style != ) {
            throw new IllegalArgumentException("Illegal style: " + style);
        }
        String id = getID();
        String[] names = getDisplayNames(idlocale);
        if (names == null) {
            if (id.startsWith("GMT")) {
                char sign = id.charAt(3);
                if (sign == '+' || sign == '-') {
                    return id;
                }
            }
            int offset = getRawOffset();
            if (daylight) {
                offset += getDSTSavings();
            }
            return ZoneInfoFile.toCustomID(offset);
        }
        int index = daylight ? 3 : 1;
        if (style == ) {
            index++;
        }
        return names[index];
    }
    private static class DisplayNames {
        // Cache for managing display names per timezone per locale
        // The structure is:
        //   Map(key=id, value=SoftReference(Map(key=locale, value=displaynames)))
        private static final Map<StringSoftReference<Map<LocaleString[]>>> CACHE =
            new ConcurrentHashMap<StringSoftReference<Map<LocaleString[]>>>();
    }
    private static final String[] getDisplayNames(String idLocale locale) {
        Map<StringSoftReference<Map<LocaleString[]>>> displayNames = .;
        SoftReference<Map<LocaleString[]>> ref = displayNames.get(id);
        if (ref != null) {
            Map<LocaleString[]> perLocale = ref.get();
            if (perLocale != null) {
                String[] names = perLocale.get(locale);
                if (names != null) {
                    return names;
                }
                names = TimeZoneNameUtility.retrieveDisplayNames(idlocale);
                if (names != null) {
                    perLocale.put(localenames);
                }
                return names;
            }
        }
        String[] names = TimeZoneNameUtility.retrieveDisplayNames(idlocale);
        if (names != null) {
            Map<LocaleString[]> perLocale = new ConcurrentHashMap<LocaleString[]>();
            perLocale.put(localenames);
            ref = new SoftReference<Map<LocaleString[]>>(perLocale);
            displayNames.put(idref);
        }
        return names;
    }

    
Returns the amount of time to be added to local standard time to get local wall clock time.

The default implementation always returns 3600000 milliseconds (i.e., one hour) if this time zone observes Daylight Saving Time. Otherwise, 0 (zero) is returned.

If an underlying TimeZone implementation subclass supports historical Daylight Saving Time changes, this method returns the known latest daylight saving value.

Returns:
the amount of saving time in milliseconds
Since:
1.4
    public int getDSTSavings() {
        if (useDaylightTime()) {
            return 3600000;
        }
        return 0;
    }

    
Queries if this time zone uses daylight savings time.

If an underlying TimeZone implementation subclass supports historical Daylight Saving Time schedule changes, the method refers to the latest Daylight Saving Time schedule information.

Returns:
true if this time zone uses daylight savings time, false, otherwise.
    public abstract boolean useDaylightTime();

    
Queries if the given date is in daylight savings time in this time zone.

Parameters:
date the given Date.
Returns:
true if the given date is in daylight savings time, false, otherwise.
    abstract public boolean inDaylightTime(Date date);

    
Gets the TimeZone for the given ID.

Parameters:
ID the ID for a TimeZone, either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "GMT-8:00". Note that the support of abbreviations is for JDK 1.1.x compatibility only and full names should be used.
Returns:
the specified TimeZone, or the GMT zone if the given ID cannot be understood.
    public static synchronized TimeZone getTimeZone(String ID) {
        return getTimeZone(IDtrue);
    }
    private static TimeZone getTimeZone(String IDboolean fallback) {
        TimeZone tz = ZoneInfo.getTimeZone(ID);
        if (tz == null) {
            tz = parseCustomTimeZone(ID);
            if (tz == null && fallback) {
                tz = new ZoneInfo(, 0);
            }
        }
        return tz;
    }

    
Gets the available IDs according to the given time zone offset in milliseconds.

Parameters:
rawOffset the given time zone GMT offset in milliseconds.
Returns:
an array of IDs, where the time zone for that ID has the specified GMT offset. For example, "America/Phoenix" and "America/Denver" both have GMT-07:00, but differ in daylight savings behavior.
See also:
getRawOffset()
    public static synchronized String[] getAvailableIDs(int rawOffset) {
        return ZoneInfo.getAvailableIDs(rawOffset);
    }

    
Gets all the available IDs supported.

Returns:
an array of IDs.
    public static synchronized String[] getAvailableIDs() {
        return ZoneInfo.getAvailableIDs();
    }

    
Gets the platform defined TimeZone ID.
    private static native String getSystemTimeZoneID(String javaHome,
                                                     String country);

    
Gets the custom time zone ID based on the GMT offset of the platform. (e.g., "GMT+08:00")
    private static native String getSystemGMTOffsetID();

    
Gets the default TimeZone for this host. The source of the default TimeZone may vary with implementation.

Returns:
a default TimeZone.
See also:
setDefault(java.util.TimeZone)
    public static TimeZone getDefault() {
        return (TimeZonegetDefaultRef().clone();
    }

    
Returns the reference to the default TimeZone object. This method doesn't create a clone.
    static TimeZone getDefaultRef() {
        TimeZone defaultZone = .get();
        if (defaultZone == null) {
            defaultZone = ;
            if (defaultZone == null) {
                // Need to initialize the default time zone.
                defaultZone = setDefaultZone();
                assert defaultZone != null;
            }
        }
        // Don't clone here.
        return defaultZone;
    }
    private static synchronized TimeZone setDefaultZone() {
        TimeZone tz = null;
        // get the time zone ID from the system properties
        String zoneID = AccessController.doPrivileged(
                new GetPropertyAction("user.timezone"));
        // if the time zone ID is not set (yet), perform the
        // platform to Java time zone ID mapping.
        if (zoneID == null || zoneID.equals("")) {
            String country = AccessController.doPrivileged(
                    new GetPropertyAction("user.country"));
            String javaHome = AccessController.doPrivileged(
                    new GetPropertyAction("java.home"));
            try {
                zoneID = getSystemTimeZoneID(javaHomecountry);
                if (zoneID == null) {
                    zoneID = ;
                }
            } catch (NullPointerException e) {
                zoneID = ;
            }
        }
        // Get the time zone for zoneID. But not fall back to
        // "GMT" here.
        tz = getTimeZone(zoneIDfalse);
        if (tz == null) {
            // If the given zone ID is unknown in Java, try to
            // get the GMT-offset-based time zone ID,
            // a.k.a. custom time zone ID (e.g., "GMT-08:00").
            String gmtOffsetID = getSystemGMTOffsetID();
            if (gmtOffsetID != null) {
                zoneID = gmtOffsetID;
            }
            tz = getTimeZone(zoneIDtrue);
        }
        assert tz != null;
        final String id = zoneID;
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
                public Object run() {
                    System.setProperty("user.timezone"id);
                    return null;
                }
            });
        if (hasPermission()) {
             = tz;
        } else {
            .set(tz);
        }
        return tz;
    }
    private static boolean hasPermission() {
        boolean hasPermission = true;
        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            try {
                sm.checkPermission(new PropertyPermission
                                   ("user.timezone""write"));
            } catch (SecurityException e) {
                hasPermission = false;
            }
        }
        return hasPermission;
    }

    
Sets the TimeZone that is returned by the getDefault method. If zone is null, reset the default to the value it had originally when the VM first started.

Parameters:
zone the new default time zone
See also:
getDefault()
    public static void setDefault(TimeZone zone)
    {
        if (hasPermission()) {
            synchronized (TimeZone.class) {
                 = zone;
            }
        } else {
            .set(zone);
        }
    }

    
Returns true if this zone has the same rule and offset as another zone. That is, if this zone differs only in ID, if at all. Returns false if the other zone is null.

Parameters:
other the TimeZone object to be compared with
Returns:
true if the other zone is not null and is the same as this one, with the possible exception of the ID
Since:
1.2
    public boolean hasSameRules(TimeZone other) {
        return other != null && getRawOffset() == other.getRawOffset() &&
            useDaylightTime() == other.useDaylightTime();
    }

    
Creates a copy of this TimeZone.

Returns:
a clone of this TimeZone
    public Object clone()
    {
        try {
            TimeZone other = (TimeZonesuper.clone();
            other.ID = ;
            return other;
        } catch (CloneNotSupportedException e) {
            throw new InternalError();
        }
    }

    
The null constant as a TimeZone.
    static final TimeZone NO_TIMEZONE = null;
    // =======================privates===============================

    
The string identifier of this TimeZone. This is a programmatic identifier used internally to look up TimeZone objects from the system table and also to map them to their localized display names. ID values are unique in the system table but may not be for dynamically created zones.

Serial:
    private String           ID;
    private static volatile TimeZone defaultTimeZone;
    private static final InheritableThreadLocal<TimeZonedefaultZoneTL
                                        = new InheritableThreadLocal<TimeZone>();
    static final String         GMT_ID        = "GMT";
    private static final int    GMT_ID_LENGTH = 3;

    
Parses a custom time zone identifier and returns a corresponding zone. This method doesn't support the RFC 822 time zone format. (e.g., +hhmm)

Parameters:
id a string of the custom ID form.
Returns:
a newly created TimeZone with the given offset and no daylight saving time, or null if the id cannot be parsed.
    private static final TimeZone parseCustomTimeZone(String id) {
        int length;
        // Error if the length of id isn't long enough or id doesn't
        // start with "GMT".
        if ((length = id.length()) < ( + 2) ||
            id.indexOf() != 0) {
            return null;
        }
        ZoneInfo zi;
        // First, we try to find it in the cache with the given
        // id. Even the id is not normalized, the returned ZoneInfo
        // should have its normalized id.
        zi = ZoneInfoFile.getZoneInfo(id);
        if (zi != null) {
            return zi;
        }
        int index = ;
        boolean negative = false;
        char c = id.charAt(index++);
        if (c == '-') {
            negative = true;
        } else if (c != '+') {
            return null;
        }
        int hours = 0;
        int num = 0;
        int countDelim = 0;
        int len = 0;
        while (index < length) {
            c = id.charAt(index++);
            if (c == ':') {
                if (countDelim > 0) {
                    return null;
                }
                if (len > 2) {
                    return null;
                }
                hours = num;
                countDelim++;
                num = 0;
                len = 0;
                continue;
            }
            if (c < '0' || c > '9') {
                return null;
            }
            num = num * 10 + (c - '0');
            len++;
        }
        if (index != length) {
            return null;
        }
        if (countDelim == 0) {
            if (len <= 2) {
                hours = num;
                num = 0;
            } else {
                hours = num / 100;
                num %= 100;
            }
        } else {
            if (len != 2) {
                return null;
            }
        }
        if (hours > 23 || num > 59) {
            return null;
        }
        int gmtOffset =  (hours * 60 + num) * 60 * 1000;
        if (gmtOffset == 0) {
            zi = ZoneInfoFile.getZoneInfo();
            if (negative) {
                zi.setID("GMT-00:00");
            } else {
                zi.setID("GMT+00:00");
            }
        } else {
            zi = ZoneInfoFile.getCustomTimeZone(idnegative ? -gmtOffset : gmtOffset);
        }
        return zi;
    }
New to GrepCode? Check out our FAQ X