Is "GMT" an Abbreviation in Java TimeZone and if So is it OK to use it? -
according javadoc timezone...
id - id timezone, either abbreviation such "pst", full name such "america/los_angeles", or custom id such "gmt-8:00". note support of abbreviations jdk 1.1.x compatibility , full names should used.
the important point being...
an abbreviation such "pst" , note support of abbreviations jdk 1.1.x compatibility , full names should used.
does mean "gmt-0:00" ok "gmt" should avoided or "gmt" not considered abbreviation?
similar other question trying make more specific.
just looked @ source code. if read correctly, gettimezone(string id) calls private method called parsecustomtimezone, checks if id starts gmt , returns null otherwise in case gettimezone falls default timezone gmt+ 0. things utc, pst, etc. supported in zoneinfo, sun internal class. can list available timezones javadoc mentions. here's bits of code relevant in timezone:
public static synchronized timezone gettimezone(string id) { return gettimezone(id, true); } ... private static timezone gettimezone(string id, boolean fallback) { timezone tz = zoneinfo.gettimezone(id); if (tz == null) { tz = parsecustomtimezone(id); if (tz == null && fallback) { tz = new zoneinfo(gmt_id, 0); } } return tz; } ... private static final timezone parsecustomtimezone(string id) { int length; // error if length of id isn't long enough or id doesn't // start "gmt". if ((length = id.length()) < (gmt_id_length + 2) || id.indexof(gmt_id) != 0) { return null; } ...
if on java 8, pretty want not use , instead use new time api. otherwise, use joda time.
Comments
Post a Comment