List of utility methods to do TimeZone Get
long | getNextHour(final String timezone) Gets the milliseconds of the nearest hour in timezone. final Calendar time = Calendar.getInstance(TimeZone.getTimeZone(timezone)); time.set(Calendar.MINUTE, 0); time.set(Calendar.SECOND, 0); time.set(Calendar.MILLISECOND, 0); time.add(Calendar.HOUR, 1); return time.getTimeInMillis(); |
ArrayList | getPossibleUserTimezoneList(int userOffsetInHours) Add possible client list from it's current GMT offset in hours We add the xones for the current offest and also the ones for offset-1 and offset+1 because we have no way to know (or at leats that i know of) wether the client is currently in Daylight savings or not by adding the 1hour before and after timezones this should cover the potential offsets at those times of the year where the client is in DST but GMT is not yet. ArrayList list = new ArrayList(); String[] s1 = TimeZone.getAvailableIDs(userOffsetInHours * 3600000); for (int i = 0; i != s1.length; i++) { list.add(s1[i]); s1 = TimeZone.getAvailableIDs((userOffsetInHours - 1) * 3600000); for (int i = 0; i != s1.length; i++) { list.add(s1[i]); ... |
long | getRawOffset(String timeZoneStr) get Raw Offset return TimeZone.getTimeZone(timeZoneStr).getRawOffset();
|
int | getRawOffsetDifference(TimeZone from, TimeZone to) get Raw Offset Difference int offsetBefore = from.getRawOffset(); int offsetAfter = to.getRawOffset(); return offsetAfter - offsetBefore; |
Integer | getServerTimezoneOffset() get Server Timezone Offset Calendar cal = Calendar.getInstance();
Integer tz = -(cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (60 * 1000);
return tz;
|
long | getTime(boolean lenient, TimeZone tz, int year, int month, int day, int hour, int minute, int second, boolean setMillis, int nano) get Time Calendar c; if (tz == null) { c = Calendar.getInstance(); } else { c = Calendar.getInstance(tz); c.setLenient(lenient); if (year <= 0) { ... |
Calendar | getTime(final String time, final TimeZone tz) get Time int hours, minutes; StringTokenizer st = new StringTokenizer(time, ":"); int tokens = st.countTokens(); if (tokens != 2) { String msg = "Time " + time + " does not conform to the HH:MM format."; throw new Exception(msg); String hourToken = st.nextToken(); ... |
long | getTime(TimeZone tz, int year, int month, int day, int hour, int minute, int second) get Time Calendar c = Calendar.getInstance(tz); c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, month - 1); c.set(Calendar.DAY_OF_MONTH, day); c.set(Calendar.HOUR_OF_DAY, hour); c.set(Calendar.MINUTE, minute); c.set(Calendar.SECOND, second); c.set(Calendar.MILLISECOND, 0); ... |
Calendar | getTime(TimeZone zone)getTime (timezone): get the time now
return Calendar.getInstance(zone);
|
String | getTimeAsPerTimeZone(String time, String timeZOne) Gets the time as per time zone. time = time.split("Minutes")[1]; DateFormat formatter = new SimpleDateFormat("hh:mm a"); TimeZone tz = TimeZone.getTimeZone("EST5EDT"); Calendar cal = new GregorianCalendar(tz); cal.add(Calendar.MINUTE, Integer.parseInt(time)); formatter.setTimeZone(tz); return formatter.format(cal.getTime()); |