Java Utililty Methods TimeZone Create

List of utility methods to do TimeZone Create

Description

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

Method

StringgetTimeZone(Date date)
get Time Zone
DateFormat xpathTimezoneFormat = new SimpleDateFormat("Z");
String timeZone = xpathTimezoneFormat.format(date);
return timeZone.substring(0, timeZone.length() - 2) + ':' + timeZone.substring(timeZone.length() - 2);
StringgetTimeZone(final Calendar cal)
Returns the time zone designator in a ISO6601-compliant format from the given Calendar value.
StringBuilder buf = new StringBuilder();
TimeZone tz = cal.getTimeZone();
int offset = tz.getOffset(cal.getTimeInMillis());
int hours = Math.abs((offset / (60 * 1000)) / 60);
int minutes = Math.abs((offset / (60 * 1000)) % 60);
buf.append(offset < 0 ? '-' : '+');
buf.append(XX_FORMAT.format(hours));
buf.append(':');
...
TimeZonegetTimeZone(final String id)
get Time Zone
if (id == null)
    return TimeZone.getDefault();
else
    return TimeZone.getTimeZone(id);
TimeZonegetTimeZone(final String tzId)
Gets the time zone.
if (tzId == null) {
    throw new IllegalArgumentException("getTimeZone");
TimeZone tz = TimeZone.getTimeZone(tzId);
if (!tz.getID().equals(tzId)) {
    throw new IllegalArgumentException("getTimeZone");
return tz;
...
TimeZonegetTimeZone(int rawoffset)
get Time Zone
String[] timeZoneIds = TimeZone.getAvailableIDs(rawoffset);
if (timeZoneIds.length == 0) {
    return TimeZone.getDefault();
TimeZone result = TimeZone.getTimeZone(timeZoneIds[0]);
return null == result ? TimeZone.getDefault() : result;
TimeZonegetTimeZone(String id)
This method performs the task analogous to TimeZone.getTimeZone(), but will return null on failure (rather than GMT).
if (id == null || id.length() == 0)
    return null;
TimeZone result = TimeZone.getTimeZone(id);
if ("GMT".equals(result.getID()) && !"GMT".equals(id))
    return null;
return result;
java.util.TimeZonegetTimeZone(String idParam)
get Time Zone
if (idParam == null || idParam.isEmpty()) {
    throw new IllegalArgumentException("id for time zone cannot be null or empty");
idParam = idParam.trim();
String[] tzArray = java.util.TimeZone.getAvailableIDs();
for (String id : tzArray) {
    if (id.equalsIgnoreCase(idParam)) {
        return java.util.TimeZone.getTimeZone(id);
...
TimeZonegetTimeZone(String timeZone)
get Time Zone
timeZone = timeZone.trim();
TimeZone zone = TimeZone.getTimeZone(timeZone);
String id = zone.getID();
if (id.compareTo(timeZone) != 0) {
    throw new IllegalArgumentException("Bad timezone name: '" + timeZone + "'");
return zone;
TimeZonegetTimeZone(String timeZone)
This gets the TimeZone object for the given string.
if (timeZone.equalsIgnoreCase(LOCAL_TIME)) {
    return TimeZone.getDefault();
return TimeZone.getTimeZone(timeZone);
TimeZonegetTimeZone(String timeZoneId)
Gets the time zone form id.
return TimeZone.getTimeZone(timeZoneId);