Java Utililty Methods TimeZone String Parse

List of utility methods to do TimeZone String Parse

Description

The list of methods to do TimeZone String Parse are organized into topic(s).

Method

TimeZoneguessTimeZone(String timezoneOffset)
guess Time Zone
return offsetMap.get(timezoneOffset.trim());
CalendarparseCal(long time, TimeZone to)
parse Cal
Calendar calendar = Calendar.getInstance();
TimeZone fromTimeZone = calendar.getTimeZone();
TimeZone toTimeZone = to != null ? to : TimeZone.getTimeZone("GMT");
calendar.setTimeZone(fromTimeZone);
calendar.add(Calendar.MILLISECOND, fromTimeZone.getRawOffset() * -1);
if (fromTimeZone.inDaylightTime(calendar.getTime())) {
    calendar.add(Calendar.MILLISECOND, calendar.getTimeZone().getDSTSavings() * -1);
calendar.add(Calendar.MILLISECOND, toTimeZone.getRawOffset());
if (toTimeZone.inDaylightTime(calendar.getTime())) {
    calendar.add(Calendar.MILLISECOND, toTimeZone.getDSTSavings());
calendar.setTimeInMillis(time);
return calendar;
DateparseDA(TimeZone tz, String s)
parse DA
return parseDA(tz, s, false);
TimeZoneparseTimeZoneId(String timeZoneId)
parse Time Zone Id
TimeZone zone = TimeZone.getDefault();
String zoneName = "";
if (null != timeZoneId && !"".equals(timeZoneId)) {
    timeZoneId = timeZoneId.trim().replaceAll("\\s+", "");
    int index2 = timeZoneId.indexOf(")");
    if (index2 >= 0) {
        zoneName = timeZoneId.substring(index2 + 1, timeZoneId.length()).trim();
    zone = TimeZone.getTimeZone(zoneName);
return zone;
TimeZoneparseTimeZoneString(String timeZoneString)
Parse the given timeZoneString value into a TimeZone .
TimeZone timeZone = TimeZone.getTimeZone(timeZoneString);
if ("GMT".equals(timeZone.getID()) && !timeZoneString.startsWith("GMT")) {
    throw new IllegalArgumentException("Invalid time zone specification '" + timeZoneString + "'");
return timeZone;
TimeZoneparseTimeZoneString(String timeZoneString)
parse Time Zone String
TimeZone timeZone = TimeZone.getTimeZone(timeZoneString);
if ("GMT".equals(timeZone.getID()) && !timeZoneString.startsWith("GMT")) {
    throw new IllegalArgumentException("Invalid time zone specification '" + timeZoneString + "'");
return timeZone;
TimeZonesafeTimeZone(String s)
safe Time Zone
String tzid = tzid(s);
if (tzid == null)
    return null;
TimeZone tz = cachedTimeZone;
if (tz == null || !tz.getID().equals(tzid))
    cachedTimeZone = tz = TimeZone.getTimeZone(tzid);
return tz;