List of usage examples for java.util TimeZone getRawOffset
public abstract int getRawOffset();
From source file:org.jumpmind.db.platform.AbstractDatabasePlatform.java
public TimeZone getTimeZone(String value) { TimeZone tz = TimeZone.getTimeZone("GMT" + value); // try as an offset. ("-05:00") if (tz.getRawOffset() == 0) { tz = TimeZone.getTimeZone(value); // try as a raw code. e.g. "EST" }//ww w . j a va2 s .c o m return tz; }
From source file:tw.com.sti.store.api.android.AndroidApiService.java
public List<NameValuePair> createRequestParams(String[] paramNames, String[] paramValues, boolean withToken, Integer appfilter, String userId, String pwd) { List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("store", storeId)); nvps.add(new BasicNameValuePair("aver", sdkVer)); nvps.add(new BasicNameValuePair("arel", sdkRel)); nvps.add(new BasicNameValuePair("cver", clientVer)); nvps.add(new BasicNameValuePair("lang", Locale.getDefault().toString())); TimeZone tz = TimeZone.getDefault(); nvps.add(new BasicNameValuePair("tzid", tz.getID())); nvps.add(new BasicNameValuePair("tzrawoffset", "" + tz.getRawOffset())); String time = "" + System.currentTimeMillis(); nvps.add(new BasicNameValuePair("time", time)); String vstring = storeId + "|" + time; if (userId != null && pwd != null) { vstring = storeId + "|" + time + "|" + userId + "|" + pwd; } else if (withToken && this.credential.getToken() != null && this.credential.getToken().length() > 0) { vstring = storeId + "|" + time + "|" + this.credential.getToken(); } else if (deviceId != null && subscriberId != null && simSerialNumber != null) { vstring = storeId + "|" + time + "|" + deviceId + "|" + subscriberId + "|" + simSerialNumber; }/*ww w. j a v a 2s . c o m*/ L.d("vstring=" + vstring); String vsign = ""; try { vsign = Dsa.sign(vstring, this.config.getApiPrivkey()); } catch (Exception e) { } nvps.add(new BasicNameValuePair("vsign", vsign)); nvps.add(new BasicNameValuePair("imei", deviceId)); nvps.add(new BasicNameValuePair("mac", macAddress)); nvps.add(new BasicNameValuePair("imsi", subscriberId)); nvps.add(new BasicNameValuePair("iccid", simSerialNumber)); nvps.add(new BasicNameValuePair("dvc", Build.MODEL)); nvps.add(new BasicNameValuePair("wpx", wpx)); nvps.add(new BasicNameValuePair("hpx", hpx)); if (appfilter == null) { //?appFilter() nvps.add(new BasicNameValuePair("appfilter", "" + appFilter)); } else { //?appfilter nvps.add(new BasicNameValuePair("appfilter", "" + appfilter)); } //??? if (this.config.getSnum() != null && this.config.getSnum().length() > 0) { nvps.add(new BasicNameValuePair("snum", this.config.getSnum())); } if (withToken && this.credential.getToken() != null && this.credential.getToken().length() > 0) { nvps.add(new BasicNameValuePair("token", this.credential.getToken())); } if (paramNames == null || paramValues == null) { return nvps; } if (paramNames.length != paramValues.length) { throw new IndexOutOfBoundsException("paramNames.length != paramValues.length"); } int count = paramNames.length; for (int i = 0; i < count; i++) { nvps.add(new BasicNameValuePair(paramNames[i], paramValues[i])); } return nvps; }
From source file:com.ecyrd.jspwiki.ui.TemplateManager.java
/** * List all timezones, with special marker for server timezone * /*from ww w . ja va2s. c o m*/ * @param pageContext * @return map of TimeZones * @since 2.7.x */ public Map listTimeZones(PageContext pageContext) { LinkedHashMap<String, String> resultMap = new LinkedHashMap<String, String>(); String[][] tzs = { { "GMT-12", "Enitwetok, Kwajalien" }, { "GMT-11", "Nome, Midway Island, Samoa" }, { "GMT-10", "Hawaii" }, { "GMT-9", "Alaska" }, { "GMT-8", "Pacific Time" }, { "GMT-7", "Mountain Time" }, { "GMT-6", "Central Time, Mexico City" }, { "GMT-5", "Eastern Time, Bogota, Lima, Quito" }, { "GMT-4", "Atlantic Time, Caracas, La Paz" }, { "GMT-3:30", "Newfoundland" }, { "GMT-3", "Brazil, Buenos Aires, Georgetown, Falkland Is." }, { "GMT-2", "Mid-Atlantic, Ascention Is., St Helena" }, { "GMT-1", "Azores, Cape Verde Islands" }, { "GMT", "Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia" }, { "GMT+1", "Berlin, Brussels, Copenhagen, Madrid, Paris, Rome" }, { "GMT+2", "Helsinki, Athens, Kaliningrad, South Africa, Warsaw" }, { "GMT+3", "Baghdad, Riyadh, Moscow, Nairobi" }, { "GMT+3:30", "Tehran" }, { "GMT+4", "Adu Dhabi, Baku, Muscat, Tbilisi" }, { "GMT+4:30", "Kabul" }, { "GMT+5", "Islamabad, Karachi, Tashkent" }, { "GMT+5:30", "Bombay, Calcutta, Madras, New Delhi" }, { "GMT+6", "Almaty, Colomba, Dhakra" }, { "GMT+7", "Bangkok, Hanoi, Jakarta" }, { "GMT+8", "Beijing, Hong Kong, Perth, Singapore, Taipei" }, { "GMT+9", "Osaka, Sapporo, Seoul, Tokyo, Yakutsk" }, { "GMT+9:30", "Adelaide, Darwin" }, { "GMT+10", "Melbourne, Papua New Guinea, Sydney, Vladivostok" }, { "GMT+11", "Magadan, New Caledonia, Solomon Islands" }, { "GMT+12", "Auckland, Wellington, Fiji, Marshall Island" } }; java.util.TimeZone servertz = java.util.TimeZone.getDefault(); for (int i = 0; i < tzs.length; i++) { String tzID = tzs[i][0]; java.util.TimeZone tz = java.util.TimeZone.getTimeZone(tzID); String serverTimeZone = ""; if (servertz.getRawOffset() == tz.getRawOffset()) { serverTimeZone = LocaleSupport.getLocalizedMessage(pageContext, I18NSERVER_TIMEZONE); tzID = servertz.getID(); } resultMap.put(tzID, "(" + tzs[i][0] + ") " + tzs[i][1] + " " + serverTimeZone); } return resultMap; }
From source file:net.solarnetwork.web.support.SimpleXmlView.java
/** * Create a {@link SimpleDateFormat} and cache on the {@link #SDF} * ThreadLocal to re-use for all dates within a single response. * //from w ww . j a va 2s . c o m * @param model * the model, to look for a TimeZone to format the dates in */ private Map<String, Object> setupDateFormat(Map<String, Object> model) { TimeZone tz = TimeZone.getTimeZone("GMT"); Map<String, Object> result = new LinkedHashMap<String, Object>(); for (Map.Entry<String, Object> me : model.entrySet()) { Object o = me.getValue(); if (useModelTimeZoneForDates && o instanceof TimeZone) { tz = (TimeZone) o; } else if (modelKey != null) { if (modelKey.equals(me.getKey())) { result.put(modelKey, o); } } else { //if ( !(o instanceof BindingResult) ) { result.put(me.getKey(), o); } } SimpleDateFormat sdf = new SimpleDateFormat(); if (tz.getRawOffset() == 0) { sdf.applyPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); } else { sdf.applyPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); } sdf.setTimeZone(tz); if (logger.isTraceEnabled()) { logger.trace("TZ offset " + tz.getRawOffset()); } SDF.set(sdf); return result; }
From source file:net.solarnetwork.util.JavaBeanXmlSerializer.java
/** * Create a {@link SimpleDateFormat} and cache on the {@link #SDF} * ThreadLocal to re-use for all dates within a single response. * //from w w w. jav a2 s. c o m * @param model * the model, to look for a TimeZone to format the dates in */ private Map<String, Object> setupDateFormat(Map<String, ?> model) { TimeZone tz = TimeZone.getTimeZone("GMT"); Map<String, Object> result = null; if (model != null) { result = new LinkedHashMap<String, Object>(); for (Map.Entry<String, ?> me : model.entrySet()) { Object o = me.getValue(); if (useModelTimeZoneForDates && o instanceof TimeZone) { tz = (TimeZone) o; } else if (modelKey != null) { if (modelKey.equals(me.getKey())) { result.put(modelKey, o); } } else { result.put(me.getKey(), o); } } } SimpleDateFormat sdf = new SimpleDateFormat(); if (tz.getRawOffset() == 0) { sdf.applyPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); } else { sdf.applyPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); } sdf.setTimeZone(tz); if (logger.isTraceEnabled()) { logger.trace("TZ offset " + tz.getRawOffset()); } SDF.set(sdf); return result; }
From source file:com.alibaba.wasp.jdbc.TestJdbcResultSet.java
public void testDatetimeWithCalendar() throws SQLException { trace("test DATETIME with Calendar"); ResultSet rs;/*from www . j a va2 s. c om*/ stat = conn.createStatement(); stat.execute("CREATE TABLE test(ID INT PRIMARY KEY, D DATE, T TIME, TS TIMESTAMP)"); PreparedStatement prep = conn.prepareStatement("INSERT INTO test VALUES(?, ?, ?, ?)"); Calendar regular = Calendar.getInstance(); Calendar other = null; // search a locale that has a _different_ raw offset long testTime = java.sql.Date.valueOf("2001-02-03").getTime(); for (String s : TimeZone.getAvailableIDs()) { TimeZone zone = TimeZone.getTimeZone(s); long rawOffsetDiff = regular.getTimeZone().getRawOffset() - zone.getRawOffset(); // must not be the same timezone (not 0 h and not 24 h difference // as for Pacific/Auckland and Etc/GMT+12) if (rawOffsetDiff != 0 && rawOffsetDiff != 1000 * 60 * 60 * 24) { if (regular.getTimeZone().getOffset(testTime) != zone.getOffset(testTime)) { other = Calendar.getInstance(zone); break; } } } trace("regular offset = " + regular.getTimeZone().getRawOffset() + " other = " + other.getTimeZone().getRawOffset()); prep.setInt(1, 0); prep.setDate(2, null, regular); prep.setTime(3, null, regular); prep.setTimestamp(4, null, regular); prep.execute(); prep.setInt(1, 1); prep.setDate(2, null, other); prep.setTime(3, null, other); prep.setTimestamp(4, null, other); prep.execute(); prep.setInt(1, 2); prep.setDate(2, java.sql.Date.valueOf("2001-02-03"), regular); prep.setTime(3, java.sql.Time.valueOf("04:05:06"), regular); prep.setTimestamp(4, Timestamp.valueOf("2007-08-09 10:11:12.131415"), regular); prep.execute(); prep.setInt(1, 3); prep.setDate(2, java.sql.Date.valueOf("2101-02-03"), other); prep.setTime(3, java.sql.Time.valueOf("14:05:06"), other); prep.setTimestamp(4, Timestamp.valueOf("2107-08-09 10:11:12.131415"), other); prep.execute(); prep.setInt(1, 4); prep.setDate(2, java.sql.Date.valueOf("2101-02-03")); prep.setTime(3, java.sql.Time.valueOf("14:05:06")); prep.setTimestamp(4, Timestamp.valueOf("2107-08-09 10:11:12.131415")); prep.execute(); rs = stat.executeQuery("SELECT * FROM test ORDER BY ID"); assertResultSetMeta(rs, 4, new String[] { "ID", "D", "T", "TS" }, new int[] { Types.INTEGER, Types.DATE, Types.TIME, Types.TIMESTAMP }, new int[] { 10, 8, 6, 23 }, new int[] { 0, 0, 0, 10 }); rs.next(); assertEquals(0, rs.getInt(1)); assertTrue(rs.getDate(2, regular) == null && rs.wasNull()); assertTrue(rs.getTime(3, regular) == null && rs.wasNull()); assertTrue(rs.getTimestamp(3, regular) == null && rs.wasNull()); rs.next(); assertEquals(1, rs.getInt(1)); assertTrue(rs.getDate(2, other) == null && rs.wasNull()); assertTrue(rs.getTime(3, other) == null && rs.wasNull()); assertTrue(rs.getTimestamp(3, other) == null && rs.wasNull()); rs.next(); assertEquals(2, rs.getInt(1)); assertEquals("2001-02-03", rs.getDate(2, regular).toString()); assertEquals("04:05:06", rs.getTime(3, regular).toString()); assertFalse(rs.getTime(3, other).toString().equals("04:05:06")); assertEquals("2007-08-09 10:11:12.131415", rs.getTimestamp(4, regular).toString()); assertFalse(rs.getTimestamp(4, other).toString().equals("2007-08-09 10:11:12.131415")); rs.next(); assertEquals(3, rs.getInt("ID")); assertFalse(rs.getTimestamp("TS", regular).toString().equals("2107-08-09 10:11:12.131415")); assertEquals("2107-08-09 10:11:12.131415", rs.getTimestamp("TS", other).toString()); assertFalse(rs.getTime("T", regular).toString().equals("14:05:06")); assertEquals("14:05:06", rs.getTime("T", other).toString()); // checkFalse(rs.getDate(2, regular).toString(), "2101-02-03"); // check(rs.getDate("D", other).toString(), "2101-02-03"); rs.next(); assertEquals(4, rs.getInt("ID")); assertEquals("2107-08-09 10:11:12.131415", rs.getTimestamp("TS").toString()); assertEquals("14:05:06", rs.getTime("T").toString()); assertEquals("2101-02-03", rs.getDate("D").toString()); assertFalse(rs.next()); stat.execute("DROP TABLE test"); }
From source file:Classes.MainForm.java
public boolean getLocationFromIP() { boolean b = false; try {/* w ww. j a va 2 s .c o m*/ URL whatismyip = new URL("http://checkip.amazonaws.com"); BufferedReader in = new BufferedReader(new InputStreamReader(whatismyip.openStream())); String ip = in.readLine(); URL url = new URL("http://freegeoip.net/json/" + ip); BufferedReader inn = new BufferedReader(new InputStreamReader(url.openStream())); String s = inn.readLine(); JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = (JSONObject) jsonParser.parse(s); country = jsonObject.get("country_name").toString(); city = jsonObject.get("city").toString(); longitude = jsonObject.get("longitude").toString(); latitude = jsonObject.get("latitude").toString(); TimeZone tz = TimeZone.getTimeZone((String) jsonObject.get("time_zone")); timezone = String.valueOf(((tz.getRawOffset()) / (60 * 60 * 1000D))); if (!country.equalsIgnoreCase("") && !city.equalsIgnoreCase("") && !longitude.equalsIgnoreCase("") && !latitude.equalsIgnoreCase("") && !timezone.equalsIgnoreCase("")) { b = true; } } catch (Exception e) { b = false; this.locationFromInternet.setEnabled(true); this.locationFromInternet.setIcon(locationfromInternetIconMain); } return b; }
From source file:com.betfair.testing.utils.cougar.helpers.CougarHelpers.java
public Date convertToSystemTimeZone(String datetoconvert) { TimeZone tz = TimeZone.getDefault(); Date date = new Date(); try {/*from w ww.ja v a 2s . c om*/ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); String s = datetoconvert; String[] tmp = s.split(".0Z"); String s1 = tmp[0]; logger.debug("given string is" + s1); date = dateFormat.parse(s1); logger.debug("OffsetValue is " + tz.getRawOffset()); if (tz.getRawOffset() != 0) date = new Date(date.getTime() + tz.getRawOffset()); logger.debug("After adding offset" + date); if (tz.inDaylightTime(date)) { Date dstDate = new Date(date.getTime() + tz.getDSTSavings()); logger.debug("Day Light Saving is " + tz.getDSTSavings()); logger.debug("Dst is " + dstDate); if (tz.inDaylightTime(dstDate)) { date = dstDate; // logger.debug("dst date "+ dstDate); } } logger.debug("After the day light saving" + date); } catch (Exception e) { logger.debug("System exception caught" + e); } return date; }
From source file:org.pentaho.reporting.platform.plugin.ParameterXmlContentHandler.java
private String computeTimeZoneHint(final ParameterDefinitionEntry parameter, final ParameterContext parameterContext) { // add a timezone hint .. final String timezoneSpec = parameter.getParameterAttribute(ParameterAttributeNames.Core.NAMESPACE, ParameterAttributeNames.Core.TIMEZONE, parameterContext); if ("client".equals(timezoneSpec))//$NON-NLS-1$ {/*from www .ja va2s. c o m*/ return (""); } else { final TimeZone timeZone; final StringBuffer value = new StringBuffer(); if (timezoneSpec == null || "server".equals(timezoneSpec))//$NON-NLS-1$ { timeZone = TimeZone.getDefault(); } else if ("utc".equals(timezoneSpec))//$NON-NLS-1$ { timeZone = TimeZone.getTimeZone("UTC");//$NON-NLS-1$ } else { timeZone = TimeZone.getTimeZone(timezoneSpec); } final int rawOffset = timeZone.getRawOffset(); if (rawOffset < 0) { value.append("-"); } else { value.append("+"); } final int seconds = Math.abs(rawOffset / 1000); final int minutesRaw = seconds / 60; final int hours = minutesRaw / 60; final int minutes = minutesRaw % 60; if (hours < 10) { value.append("0"); } value.append(hours); if (minutes < 10) { value.append("0"); } value.append(minutes); return value.toString(); } }
From source file:com.sentaroh.android.SMBExplorer.FileIo.java
public FileIo(GlobalParameters gp, int op_cd, ArrayList<FileIoLinkParm> alp, ThreadCtrl tc, NotifyEvent ne, Context cc, String lmp) { mGp = gp;/*from ww w . j av a 2 s .co m*/ fileioThreadCtrl = tc; file_op_cd = op_cd; fileioLinkParm = alp; notifyEvent = ne; mContext = cc; mSafCA = new SafCommonArea(); SafUtil.initWorkArea(cc, mSafCA, mGp.debugLevel > 0); mediaScanner = new MediaScannerConnection(mContext, new MediaScannerConnectionClient() { @Override public void onMediaScannerConnected() { sendDebugLogMsg(1, "I", "MediaScanner connected."); }; @Override public void onScanCompleted(String path, Uri uri) { sendDebugLogMsg(2, "I", "MediaScanner scan completed. fn=" + path + ", Uri=" + uri); }; }); mediaScanner.connect(); SMB_BUFF_SIZE = Integer.parseInt(mGp.jcifs_option_iobuff) * 65536; TimeZone tz = TimeZone.getDefault(); mTimeZoneDiff = tz.getRawOffset(); if (lmp != null && lmp.startsWith("/")) { if (isAppSpecificDirectoryExists(cc, lmp)) { sendDebugLogMsg(1, "I", "Local file last modified time was reset by application specific directory"); mGp.useSetLastModifiedByAppSpecificDir = true; if (lmp.contains("/Android/data/" + mAppPackageName + "/files")) mAppSpecificDirName = lmp; else mAppSpecificDirName = lmp + "/Android/data/" + mAppPackageName + "/files"; } else { if (!isSetLastModifiedFunctional(lmp)) { if (mGp.mSuCmdProcess != null) { sendDebugLogMsg(1, "I", "Local file last modified time was set by touch command"); mGp.useSetLastModifiedByTouchCommand = true; } else { sendDebugLogMsg(1, "I", "Local file last modified time was can not reset becuase su not granted"); } } else { sendDebugLogMsg(1, "I", "Local file last modified time was set by Java File#setLastModified() method"); } } } }