Java Utililty Methods TimeZone Get

List of utility methods to do TimeZone Get

Description

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

Method

StringgetCurrentTimezoneOffset()
get Current Timezone Offset
TimeZone tz = TimeZone.getDefault();
Calendar cal = GregorianCalendar.getInstance(tz);
int offsetInMillis = tz.getOffset(cal.getTimeInMillis());
String offset = String.format("%02d:%02d", Math.abs(offsetInMillis / 3600000),
        Math.abs((offsetInMillis / 60000) % 60));
offset = (offsetInMillis >= 0 ? "+" : "-") + offset;
return offset;
CalendargetDateInTimeZone(final Date date, final TimeZone timeZone)
Get date in timezone
final Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTime(date);
return calendar;
longgetDefaultTimeZoneOffset()
Get the offset between GMT and the local timezone
long offset = 0;
TimeZone zn = TimeZone.getDefault();
Calendar local = Calendar.getInstance();
local.setTime(new Date(System.currentTimeMillis()));
int time = (int) (local.get(Calendar.HOUR_OF_DAY) * HOUR_FACTOR + local.get(Calendar.MINUTE) * MINUTE_FACTOR
        + local.get(Calendar.SECOND) * SECOND_FACTOR);
offset = zn.getOffset(1, 
        local.get(Calendar.YEAR), local.get(Calendar.MONTH), local.get(Calendar.DAY_OF_MONTH),
...
intgetDefaultTimeZoneRawOffset()
get Default Time Zone Raw Offset
return TimeZone.getDefault().getRawOffset();
StringgetDefaultTimeZoneString()
get Default Time Zone String
if (timeZone == null) {
    String s = new SimpleDateFormat("Z").format(new Date(0)); 
    timeZone = s.substring(0, 3) + ':' + s.substring(3, 5);
return timeZone;
intgetDiffTimeZoneRawOffset(String timeZoneId)
get Diff Time Zone Raw Offset
return TimeZone.getDefault().getRawOffset() - TimeZone.getTimeZone(timeZoneId).getRawOffset();
StringgetDisplayDate(Date date, TimeZone tz, Locale inLocale, int style, boolean includeTime)
Private method for getting display date for a particular style: short, medium, long or full.
if (date == null || inLocale == null) {
    return null;
if (includeTime && (tz == null)) {
    tz = TimeZone.getTimeZone("GMT");
try {
    SimpleDateFormat formatter;
...
intgetDSTSavings(TimeZone tz)

Equivalent of TimeZone.getDSTSavings() in JDK 1.4, but Quartz is trying to support JDK 1.3.

if (tz.useDaylightTime()) {
    return 3600000;
return 0;
longgetDSTTime(TimeZone tz, Date date)
get DST Time
return date.getTime() + (tz.inDaylightTime(date) ? tz.getDSTSavings() : 0);
StringgetEnd(String date, TimeZone tz)
get End
return date + " 23:59:59 " + tz.getDisplayName(true, TimeZone.SHORT);