List of utility methods to do TimeZone String Parse
TimeZone | guessTimeZone(String timezoneOffset) guess Time Zone return offsetMap.get(timezoneOffset.trim());
|
Calendar | parseCal(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; |
Date | parseDA(TimeZone tz, String s) parse DA return parseDA(tz, s, false);
|
TimeZone | parseTimeZoneId(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; |
TimeZone | parseTimeZoneString(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; |
TimeZone | parseTimeZoneString(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; |
TimeZone | safeTimeZone(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; |