public static TimeZone toTimeZone ( String strTimezone , TimeZone defaultValue ) { if ( strTimezone == null ) return defaultValue ; String strTimezoneTrimmed = StringUtil . replace ( strTimezone . trim ( ) . toLowerCase ( ) , " " , "" , false ) ; TimeZone tz = getTimeZoneFromIDS ( strTimezoneTrimmed ) ; if ( tz != null ) return tz ; // parse GMT followd by a number float gmtOffset = Float . NaN ; if ( strTimezoneTrimmed . startsWith ( "gmt" ) ) gmtOffset = getGMTOffset ( strTimezoneTrimmed . substring ( 3 ) . trim ( ) , Float . NaN ) ; else if ( strTimezoneTrimmed . startsWith ( "etc/gmt" ) ) gmtOffset = getGMTOffset ( strTimezoneTrimmed . substring ( 7 ) . trim ( ) , Float . NaN ) ; else if ( strTimezoneTrimmed . startsWith ( "utc" ) ) gmtOffset = getGMTOffset ( strTimezoneTrimmed . substring ( 3 ) . trim ( ) , Float . NaN ) ; else if ( strTimezoneTrimmed . startsWith ( "etc/utc" ) ) gmtOffset = getGMTOffset ( strTimezoneTrimmed . substring ( 7 ) . trim ( ) , Float . NaN ) ; if ( ! Float . isNaN ( gmtOffset ) ) { strTimezoneTrimmed = "etc/gmt" + ( gmtOffset >= 0 ? "+" : "" ) + Caster . toString ( gmtOffset ) ; tz = getTimeZoneFromIDS ( strTimezoneTrimmed ) ; if ( tz != null ) return tz ; } // display name in all variations if ( ! StringUtil . isEmpty ( strTimezoneTrimmed ) ) { tz = dn . get ( strTimezoneTrimmed ) ; if ( tz != null ) return tz ; Iterator < Object > it = IDS . values ( ) . iterator ( ) ; Object o ; while ( it . hasNext ( ) ) { o = it . next ( ) ; if ( o instanceof TimeZone ) { tz = ( TimeZone ) o ; if ( strTimezone . equalsIgnoreCase ( tz . getDisplayName ( true , TimeZone . SHORT , Locale . US ) ) || strTimezone . equalsIgnoreCase ( tz . getDisplayName ( false , TimeZone . SHORT , Locale . US ) ) || strTimezone . equalsIgnoreCase ( tz . getDisplayName ( true , TimeZone . LONG , Locale . US ) ) || strTimezone . equalsIgnoreCase ( tz . getDisplayName ( false , TimeZone . LONG , Locale . US ) ) ) { dn . put ( strTimezoneTrimmed , tz ) ; return tz ; } } } } return defaultValue ; }
translate timezone string format to a timezone