protected TimeZone getTimeZone(long deviceId, String defaultTimeZone) { TimeZone result = TimeZone.getTimeZone(defaultTimeZone); String timeZoneName = identityManager.lookupAttributeString(deviceId, "decoder.timezone", null, true); if (timeZoneName != null) { result = TimeZone.getTimeZone(timeZoneName); } else { int timeZoneOffset = config.getInteger(getProtocolName() + ".timezone", 0); if (timeZoneOffset != 0) { result.setRawOffset(timeZoneOffset * 1000); LOGGER.warn("Config parameter " + getProtocolName() + ".timezone is deprecated"); } } return result; }
TimeZone timeZone = deviceSession.getTimeZone(); if (timeZone.getRawOffset() == 0) { timeZone.setRawOffset(offset * 1000); deviceSession.setTimeZone(timeZone);
tz.setRawOffset(restrainTZoffset(hrSign * (tzHours * MILLIS_PER_HOUR + tzMin * (long) MILLIS_PER_MINUTE))); updateZoneId(tz);
@Override public void setRawOffset(int offset) { timeZone.setRawOffset(offset); }
/** * Sets the base time zone offset to GMT. * This is the offset to add *to* UTC to get local time. * @param offsetMillis the given base time zone offset to GMT. * @stable ICU 2.0 */ public void setRawOffset(int offsetMillis) { if (isFrozen) { throw new UnsupportedOperationException("Attempt to modify a frozen TimeZone instance."); } timeZone.setRawOffset(offsetMillis); }
/** * Sets the base time zone offset to GMT. * This is the offset to add *to* UTC to get local time. * @param offsetMillis the given base time zone offset to GMT. * @stable ICU 2.0 */ public void setRawOffset(int offsetMillis) { if (isFrozen) { throw new UnsupportedOperationException("Attempt to modify a frozen TimeZone instance."); } timeZone.setRawOffset(offsetMillis); }
/** * Creates UTC Timezone with given offset in millisec. */ public static TimeZone createUTCTimeZone(int offset) { TimeZone zone = TimeZone.getTimeZone("UTC"); if (offset != 0) { zone.setRawOffset(offset); } return zone; }
DateFormat dateFormat = new SimpleDateFormat("MMM dd, yyyy hh:mm aa zzz"); TimeZone defaultTimeZone = TimeZone.getDefault(); TimeZone timeZone = TimeZone.getTimeZone(""); timeZone.setID(defaultTimeZone.getID()); timeZone.setRawOffset(defaultTimeZone.getRawOffset()); dateFormat.setTimeZone(timeZone); System.out.println(dateFormat.format(new Date(1243861200000L)));
public void set(String value, Calendar calendar) { if (value.equals("Z")) { calendar.getTimeZone().setRawOffset(0); } else { String hs = value.substring(1, 3); String ms = value.substring(3, 5); if (hs.charAt(0) == '0') hs = hs.substring(1); if (ms.charAt(0) == '0') ms = ms.substring(1); int i = value.charAt(0) == '+' ? 1 : -1; int h = Integer.parseInt(hs); int m = Integer.parseInt(ms); calendar.getTimeZone().setRawOffset(i * (h * 60 + m) * 60000); } }
@Override public void setRawOffset(int offsetMillis) { if (isFrozen()) { throw new UnsupportedOperationException("Attempt to modify a frozen TimeZoneJDK instance."); } fJdkTz.setRawOffset(offsetMillis); }
@Override public void setRawOffset(int offsetMillis) { if (isFrozen()) { throw new UnsupportedOperationException("Attempt to modify a frozen JavaTimeZone instance."); } javatz.setRawOffset(offsetMillis); }
public void set(String value, Calendar calendar) { if (value.equals("Z")) { calendar.getTimeZone().setRawOffset(0); } else { String hs = value.substring(1, 3); String ms = value.substring(3, 5); if (hs.charAt(0) == '0') hs = hs.substring(1); if (ms.charAt(0) == '0') ms = ms.substring(1); int i = value.charAt(0) == '+' ? 1 : -1; int h = Integer.parseInt(hs); int m = Integer.parseInt(ms); calendar.getTimeZone().setRawOffset(i * (h * 60 + m) * 60000); } }
/** * Method formats a date to an iso formated string. * It will always produce the full iso format, e.g.: 2009-11-17T13:28:17.235+0100. * * @param date * the date. * @return String. */ public static String tofullISOString(final Date date) { TimeZone zone = TimeZone.getTimeZone("UTC"); zone.setRawOffset(-date.getTimezoneOffset() * 60 * 1000); Calendar cal = Calendar.getInstance(zone); cal.setTime(date); return tofullISOString(cal); }
/** * Format the value as an ISO8601 date time. * * @param value the value from the index * @param offset the timezone offset (adjust for the specified offset) * * @return the corresponding value. * * @throws ParseException if the value is not a parseable date. */ public static synchronized String toISODateTime(String value, int offset) throws ParseException { int x = findNonDigitCharacter(value); if (x != -1) throw new ParseException("Value is not a valid Lucene date", x); Date date = DateTools.stringToDate(value); // Only adjust for day light savings... TimeZone tz = TimeZone.getDefault(); int rawOffset = tz.inDaylightTime(date)? offset - ONE_HOUR_IN_MS : offset; tz.setRawOffset(rawOffset); ISO_DATETIME.setTimeZone(tz); String formatted = ISO_DATETIME.format(date); // the Java timezone does not include the required ':' return formatted.substring(0, formatted.length() - 2) + ":" + formatted.substring(formatted.length() - 2); }
/** * Build a calendar from TIMESTAMPTZWrapper. */ public static Calendar buildCalendar(TIMESTAMPTZWrapper timestampTZ) throws SQLException{ Timestamp ts = timestampTZ.getTimestamp(); TimeZone tz = timestampTZ.getTimeZone(); Calendar gCal; if(timestampTZ.isTimestampInGmt()) { gCal = Calendar.getInstance(tz); gCal.setTime(ts); } else { gCal = Calendar.getInstance(); gCal.setTime(ts); gCal.getTimeZone().setID(tz.getID()); gCal.getTimeZone().setRawOffset(tz.getRawOffset()); } return gCal; }
/** * Build a calendar from TIMESTAMPTZWrapper. */ public static Calendar buildCalendar(TIMESTAMPTZWrapper timestampTZ) throws SQLException{ Timestamp ts = timestampTZ.getTimestamp(); TimeZone tz = timestampTZ.getTimeZone(); Calendar gCal; if(timestampTZ.isTimestampInGmt()) { gCal = Calendar.getInstance(tz); gCal.setTime(ts); } else { gCal = Calendar.getInstance(); gCal.setTime(ts); gCal.getTimeZone().setID(tz.getID()); gCal.getTimeZone().setRawOffset(tz.getRawOffset()); } return gCal; }
tz.setRawOffset(restrainTZoffset(hrSign * (tzHours * MILLIS_PER_HOUR + tzMin * (long) MILLIS_PER_MINUTE))); updateZoneId(tz);
tz.setRawOffset(restrainTZoffset(hrSign * (tzHours * MILLIS_PER_HOUR + tzMin * (long) MILLIS_PER_MINUTE))); tz.setID("unknown");
tz.setRawOffset(restrainTZoffset(hrSign * (tzHours * MILLIS_PER_HOUR + tzMin * (long) MILLIS_PER_MINUTE))); updateZoneId(tz);
DATE_FORMAT.getCalendar().getTimeZone().setRawOffset(timeZoneOffset); String formattedDate = DATE_FORMAT.format(timestamp);