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

booleanisSameDayOfMillis(final long ms1, final long ms2)
is Same Day Of Millis
final long interval = ms1 - ms2;
return interval < MILLIS_IN_DAY && interval > -1L * MILLIS_IN_DAY && toDay(ms1) == toDay(ms2);
booleanisTimeZoneDisponible(TimeZone timeZone)
Verifica si una TimeZone esta disponible para su uso
String[] timeZonesIds = TimeZone.getAvailableIDs();
for (String timeZoneId : timeZonesIds) {
    if (timeZoneId.equals(timeZone.getID())) {
        return true;
return false;
booleanisValidTimeZone(final String timeZone)
is Valid Time Zone
if (timeZone.equals("GMT")) {
    return true;
} else {
    String id = TimeZone.getTimeZone(timeZone).getID();
    if (!id.equals("GMT")) {
        return true;
return false;
booleanisValidTimezone(String tz)
is Valid Timezone
if (null != tz) {
    return Arrays.asList(TimeZone.getAvailableIDs()).contains(tz);
return false;
TimeZonelocaleToTimeZone(Locale locale)
locale To Time Zone
return localeTimeZoneMap.get(locale);
StringlocalTimeZoneString()
local Time Zone String
return TimeZone.getDefault().getID();
CalendarmergeTime(Calendar date, Date time)
Set the TIME (Hour, Minute and Second) values for the start (and end mergeTime if set) to match the mergeTime (HMS) values of the given date value.
Calendar timeCalendar = Calendar.getInstance(TIMEZONE_UTC);
timeCalendar.setTime(time);
return mergeTime(date, timeCalendar);
longoffset(long time)
Gets the current timezone offset
return TimeZone.getDefault().getOffset(time);
TimeZoneparseBackendTimeZone(String timeZone)
Converts backend's TimeZone parameter to java format.
if (timeZone.startsWith("GMT")) {
    TimeZone tz = GMT_ZONES.get(timeZone);
    if (tz != null) {
        return tz;
return TimeZone.getTimeZone(timeZone);
voidrunInTimeZone(TimeZone timeZone, Runnable action)
run In Time Zone
TimeZone originalZone = TimeZone.getDefault();
try {
    TimeZone.setDefault(timeZone);
    action.run();
} finally {
    TimeZone.setDefault(originalZone);