Java Utililty Methods TimeZone Usage

List of utility methods to do TimeZone Usage

Description

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

Method

longaddGmtOffset(long millis)
add Gmt Offset
return millis + localTimeZone.getOffset(millis);
voidassertTimeZoneNotNull(String methodName, TimeZone timeZone)
assert Time Zone Not Null
if (timeZone == null) {
    String msg = "The argument 'timeZone' should not be null: method=" + methodName;
    throw new IllegalArgumentException(msg);
TimeZonebuildTimezone(int hours, int minutes)
Builds a timezone object with the given offset.
int hourMillis = 1000 * 60 * 60 * hours;
int minuteMillis = 1000 * 60 * minutes;
if (hours < 0) {
    minuteMillis *= -1;
return new SimpleTimeZone(hourMillis + minuteMillis, "");
intcomputeTimeZoneOffsetInHours(TimeZone timeZone, long currentDatetime)
Computes the offset in hours for a given timezone at a given date/time.
int offsetInMilliseconds = timeZone.getOffset(currentDatetime);
return offsetInMilliseconds / (1000 * 60 * 60);
StringcreatePostgresTimeZone()
Convert Java time zone to postgres time zone.
String tz = TimeZone.getDefault().getID();
if (tz.length() <= 3 || !tz.startsWith("GMT")) {
    return tz;
char sign = tz.charAt(3);
String start;
if (sign == '+') {
    start = "GMT-";
...
TimeZonecreateTaiTimeZone(int leapSecs)
create Tai Time Zone
return new SimpleTimeZone(leapSecs * 1000, "TAI");
DatedatePlusDays(Date date, int days)
date Plus Days
Calendar calendar = getMoscowCalendar();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_YEAR, days);
return calendar.getTime();
TimeZonefindTimeZoneInDate(String date)
find Time Zone In Date
StringBuilder sb = new StringBuilder();
StringBuilder dateBuilder = new StringBuilder(date.trim()).reverse();
int index = 0;
char c;
while ((c = dateBuilder.charAt(index++)) != ' ') {
    sb.append(c);
TimeZone timezone = TimeZone.getTimeZone(sb.reverse().toString());
...
booleanisInEasternEightZones()
is In Eastern Eight Zones
boolean defaultVaule = true;
if (TimeZone.getDefault() == TimeZone.getTimeZone("GMT+08"))
    defaultVaule = true;
else
    defaultVaule = false;
return defaultVaule;
booleanisKeepTimeZone(TimeZone tz)
is Keep Time Zone
if (tz.getID().startsWith("Africa")) { 
    return true;
} else if (tz.getID().startsWith("America")) { 
    return true;
} else if (tz.getID().startsWith("Antarctica")) { 
    return true;
} else if (tz.getID().startsWith("Asia")) { 
    return true;
...