List of utility methods to do TimeZone Usage
long | addGmtOffset(long millis) add Gmt Offset return millis + localTimeZone.getOffset(millis);
|
void | assertTimeZoneNotNull(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); |
TimeZone | buildTimezone(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, ""); |
int | computeTimeZoneOffsetInHours(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); |
String | createPostgresTimeZone() 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-"; ... |
TimeZone | createTaiTimeZone(int leapSecs) create Tai Time Zone return new SimpleTimeZone(leapSecs * 1000, "TAI"); |
Date | datePlusDays(Date date, int days) date Plus Days Calendar calendar = getMoscowCalendar();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_YEAR, days);
return calendar.getTime();
|
TimeZone | findTimeZoneInDate(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()); ... |
boolean | isInEasternEightZones() is In Eastern Eight Zones boolean defaultVaule = true; if (TimeZone.getDefault() == TimeZone.getTimeZone("GMT+08")) defaultVaule = true; else defaultVaule = false; return defaultVaule; |
boolean | isKeepTimeZone(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; ... |