Java Utililty Methods TimeZone Format

List of utility methods to do TimeZone Format

Description

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

Method

voidaddDateFormatsToList(Locale locale, TimeZone timeZone, List formats)
add Date Formats To List
for (int dateStyle = DateFormat.FULL; dateStyle <= DateFormat.SHORT; dateStyle++) {
    DateFormat df = DateFormat.getDateInstance(dateStyle, locale);
    df.setTimeZone(timeZone);
    formats.add(df);
DateFormatcreateDateFormat(String format, TimeZone tz)
create Date Format
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setTimeZone(tz);
sdf.setDateFormatSymbols(new DateFormatSymbols(Locale.US));
return sdf;
DateFormatcreateDateFormat(String pattern, TimeZone timeZone)
create Date Format
return createDateFormat(pattern, timeZone, false);
DateFormatcreateDateFormat(TimeZone timezone)
create Date Format
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
sdf.setTimeZone(timezone);
return sdf;
DateFormat[]createDateFormatsForLocaleAndTimeZone(Locale locale, TimeZone timeZone)
Build an array of DateFormats that are commonly used for this locale and timezone.
List<DateFormat> formats = new ArrayList<DateFormat>();
addDateTimeFormatsToList(locale, timeZone, formats);
addDateFormatsToList(locale, timeZone, formats);
return formats.toArray(new DateFormat[formats.size()]);
StringformatISO8601TimeZone(TimeZone timeZone, boolean extended)

Converts a TimeZone object to a string that's in ISO-8601 format.

StringBuilder sb = new StringBuilder();
boolean positive = timeZone.getRawOffset() >= 0;
int hours = Math.abs(((timeZone.getRawOffset() / 1000) / 60) / 60);
int minutes = Math.abs((timeZone.getRawOffset() / 1000) / 60) % 60;
sb.append(positive ? '+' : '-');
if (hours < 10) {
    sb.append('0');
sb.append(hours);
if (extended) {
    sb.append(':');
if (minutes < 10) {
    sb.append('0');
sb.append(minutes);
return sb.toString();
StringformatOffset(TimeZone zone)
Produce a string describing the offset of the given time zone from UTC, including the DST offset if there is one.
String fmt = "";
int base = zone.getRawOffset();
fmt += "UTC" + intervalMsToHmsShort(base);
int dst = zone.getDSTSavings();
if (dst != 0)
    fmt += " (UTC" + intervalMsToHmsShort(base + dst) + ")";
return fmt;
StringformatTimeZoneOffset(TimeZone timeZone)
Returns the formatted offset of the specified time zone at the current local time.
int offsetSeconds = timeZone.getOffset(System.currentTimeMillis()) / 1000;
int offsetHours = Math.abs(offsetSeconds / 3600);
int offsetMinutes = (Math.abs(offsetSeconds) - (offsetHours * 3600)) / 60;
StringBuilder offset = new StringBuilder("UTC");
if (offsetSeconds >= 0) {
    offset.append('+');
} else {
    offset.append('-');
...
CalendargetCalendar(String dateString, String dateTimeFormat, String timeZoneName)
get Calendar
DateFormat dateFormat = new SimpleDateFormat(dateTimeFormat);
dateFormat.setTimeZone(TimeZone.getTimeZone(timeZoneName));
Calendar disbursementCalendar = Calendar.getInstance(TimeZone.getTimeZone(timeZoneName));
disbursementCalendar.setTime(dateFormat.parse(dateString));
return disbursementCalendar;
CalendargetCalendar(String dateString, String format, TimeZone tz)
get Calendar
if (dateString == null || format == null || dateString.equals("") || tz == null)
    return null;
Calendar cal = null;
try {
    Date date = getDate(dateString, format, tz);
    cal = Calendar.getInstance();
    cal.setTime(date);
} catch (Exception ex) {
...