List of usage examples for java.util TimeZone getOffset
public int getOffset(long date)
From source file:org.exist.xquery.modules.mail.SendEmailFunction.java
/** * Returns the current date and time in an RFC822 format, suitable for an email Date Header * * @return RFC822 formated date and time as a String */// w ww. ja va2 s .co m private String getDateRFC822() { String dateString = new String(); final Calendar rightNow = Calendar.getInstance(); //Day of the week switch (rightNow.get(Calendar.DAY_OF_WEEK)) { case Calendar.MONDAY: dateString = "Mon"; break; case Calendar.TUESDAY: dateString = "Tue"; break; case Calendar.WEDNESDAY: dateString = "Wed"; break; case Calendar.THURSDAY: dateString = "Thu"; break; case Calendar.FRIDAY: dateString = "Fri"; break; case Calendar.SATURDAY: dateString = "Sat"; break; case Calendar.SUNDAY: dateString = "Sun"; break; } dateString += ", "; //Date dateString += rightNow.get(Calendar.DAY_OF_MONTH); dateString += " "; //Month switch (rightNow.get(Calendar.MONTH)) { case Calendar.JANUARY: dateString += "Jan"; break; case Calendar.FEBRUARY: dateString += "Feb"; break; case Calendar.MARCH: dateString += "Mar"; break; case Calendar.APRIL: dateString += "Apr"; break; case Calendar.MAY: dateString += "May"; break; case Calendar.JUNE: dateString += "Jun"; break; case Calendar.JULY: dateString += "Jul"; break; case Calendar.AUGUST: dateString += "Aug"; break; case Calendar.SEPTEMBER: dateString += "Sep"; break; case Calendar.OCTOBER: dateString += "Oct"; break; case Calendar.NOVEMBER: dateString += "Nov"; break; case Calendar.DECEMBER: dateString += "Dec"; break; } dateString += " "; //Year dateString += rightNow.get(Calendar.YEAR); dateString += " "; //Time String tHour = Integer.toString(rightNow.get(Calendar.HOUR_OF_DAY)); if (tHour.length() == 1) { tHour = "0" + tHour; } String tMinute = Integer.toString(rightNow.get(Calendar.MINUTE)); if (tMinute.length() == 1) { tMinute = "0" + tMinute; } String tSecond = Integer.toString(rightNow.get(Calendar.SECOND)); if (tSecond.length() == 1) { tSecond = "0" + tSecond; } dateString += tHour + ":" + tMinute + ":" + tSecond + " "; //TimeZone Correction String tzSign = new String(); String tzHours = new String(); String tzMinutes = new String(); final TimeZone thisTZ = rightNow.getTimeZone(); int tzOffset = thisTZ.getOffset(rightNow.getTime().getTime()); //get timezone offset in milliseconds tzOffset = (tzOffset / 1000); //convert to seconds tzOffset = (tzOffset / 60); //convert to minutes //Sign if (tzOffset > 1) { tzSign = "+"; } else { tzSign = "-"; tzOffset *= -1; } //Calc Hours and Minutes? if (tzOffset >= 60) { //Minutes and Hours tzHours += (tzOffset / 60); //hours // do we need to prepend a 0 if (tzHours.length() == 1) { tzHours = "0" + tzHours; } tzMinutes += (tzOffset % 60); //minutes // do we need to prepend a 0 if (tzMinutes.length() == 1) { tzMinutes = "0" + tzMinutes; } } else { //Just Minutes tzHours = "00"; tzMinutes += tzOffset; // do we need to prepend a 0 if (tzMinutes.length() == 1) { tzMinutes = "0" + tzMinutes; } } dateString += tzSign + tzHours + tzMinutes; return dateString; }
From source file:com.alibaba.wasp.jdbc.TestJdbcResultSet.java
public void testDatetimeWithCalendar() throws SQLException { trace("test DATETIME with Calendar"); ResultSet rs;/*w ww . j a v a 2 s. com*/ 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:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java
private String getDate(String timestamp) { String time = ""; DateFormat format_value = new SimpleDateFormat("h:mm a"); String str = format_value.format(Long.parseLong(timestamp) * 1000); Calendar calendar = Calendar.getInstance(); TimeZone tz = TimeZone.getDefault(); calendar.setTimeInMillis(Integer.parseInt(timestamp) * 1000L); calendar.add(Calendar.MILLISECOND, tz.getOffset(calendar.getTimeInMillis())); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String dd = formatter.format(calendar.getTime()); String datetrip[] = dd.split("-"); String WeekdayIs = new SimpleDateFormat("EEE").format(calendar.getTime()); String monthName = new SimpleDateFormat("MMM").format(calendar.getTime()); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); cal.add(Calendar.MILLISECOND, tz.getOffset(calendar.getTimeInMillis())); SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd"); String d1 = formatter1.format(cal.getTime()); String datetrip1[] = d1.split("-"); if (Integer.parseInt(datetrip1[0]) == Integer.parseInt(datetrip[0])) { if (Integer.parseInt(datetrip1[1]) == Integer.parseInt(datetrip[1])) { if (Integer.parseInt(datetrip1[2]) == Integer.parseInt(datetrip[2])) { time = "today, " + str; } else if (Integer.parseInt(datetrip1[2]) == Integer.parseInt(datetrip[2]) + 1) { time = "yesterday, " + str; } else { time = WeekdayIs + ", " + datetrip[2] + " " + monthName + ", " + datetrip[0] + ", " + str.toString(); }//w w w . j a v a2 s .c om } else { time = WeekdayIs + ", " + datetrip[2] + " " + monthName + ", " + datetrip[0] + ", " + str.toString(); } } else { time = WeekdayIs + ", " + datetrip[2] + " " + monthName + ", " + datetrip[0] + ", " + str.toString(); } return time; }
From source file:at.alladin.rmbt.controlServer.TestResultDetailResource.java
@Post("json") public String request(final String entity) { long startTime = System.currentTimeMillis(); addAllowOrigin();//ww w . j a v a 2 s .c om JSONObject request = null; final ErrorList errorList = new ErrorList(); final JSONObject answer = new JSONObject(); String answerString; final String clientIpRaw = getIP(); System.out.println(MessageFormat.format(labels.getString("NEW_TESTRESULT_DETAIL"), clientIpRaw)); if (entity != null && !entity.isEmpty()) // try parse the string to a JSON object try { request = new JSONObject(entity); String lang = request.optString("language"); JSONArray options = request.optJSONArray("options"); if (options != null) { for (int i = 0; i < options.length(); i++) { final String op = options.optString(i, null); if (op != null) { if (OPTION_WITH_KEYS.equals(op.toUpperCase(Locale.US))) { optionWithKeys = true; } } } } // Load Language Files for Client final List<String> langs = Arrays .asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*")); if (langs.contains(lang)) { errorList.setLanguage(lang); labels = ResourceManager.getSysMsgBundle(new Locale(lang)); } else lang = settings.getString("RMBT_DEFAULT_LANGUAGE"); // System.out.println(request.toString(4)); if (conn != null) { final Client client = new Client(conn); final Test test = new Test(conn); TestNdt ndt = new TestNdt(conn); final String testUuid = request.optString("test_uuid"); if (testUuid != null && test.getTestByUuid(UUID.fromString(testUuid)) > 0 && client.getClientByUid(test.getField("client_id").intValue())) { if (!ndt.loadByTestId(test.getUid())) ndt = null; final Locale locale = new Locale(lang); final Format format = new SignificantFormat(2, locale); final JSONArray resultList = new JSONArray(); final JSONObject singleItem = addObject(resultList, "time"); final Field timeField = test.getField("time"); if (!timeField.isNull()) { final Date date = ((TimestampField) timeField).getDate(); final long time = date.getTime(); singleItem.put("time", time); //csv 3 final Field timezoneField = test.getField("timezone"); if (!timezoneField.isNull()) { final String tzString = timezoneField.toString(); final TimeZone tz = TimeZone.getTimeZone(timezoneField.toString()); singleItem.put("timezone", tzString); final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale); dateFormat.setTimeZone(tz); singleItem.put("value", dateFormat.format(date)); final Format tzFormat = new DecimalFormat("+0.##;-0.##", new DecimalFormatSymbols(locale)); final float offset = tz.getOffset(time) / 1000f / 60f / 60f; addString(resultList, "timezone", String.format("UTC%sh", tzFormat.format(offset))); } } // speed download in Mbit/s (converted from kbit/s) - csv 10 (in kbit/s) final Field downloadField = test.getField("speed_download"); if (!downloadField.isNull()) { final String download = format.format(downloadField.doubleValue() / 1000d); addString(resultList, "speed_download", String.format("%s %s", download, labels.getString("RESULT_DOWNLOAD_UNIT"))); } // speed upload im MBit/s (converted from kbit/s) - csv 11 (in kbit/s) final Field uploadField = test.getField("speed_upload"); if (!uploadField.isNull()) { final String upload = format.format(uploadField.doubleValue() / 1000d); addString(resultList, "speed_upload", String.format("%s %s", upload, labels.getString("RESULT_UPLOAD_UNIT"))); } // median ping in ms final Field pingMedianField = test.getField("ping_median"); if (!pingMedianField.isNull()) { final String pingMedian = format.format(pingMedianField.doubleValue() / 1000000d); addString(resultList, "ping_median", String.format("%s %s", pingMedian, labels.getString("RESULT_PING_UNIT"))); } // signal strength RSSI in dBm - csv 13 final Field signalStrengthField = test.getField("signal_strength"); if (!signalStrengthField.isNull()) addString(resultList, "signal_strength", String.format("%d %s", signalStrengthField.intValue(), labels.getString("RESULT_SIGNAL_UNIT"))); //signal strength RSRP in dBm (LTE) - csv 29 final Field lteRsrpField = test.getField("lte_rsrp"); if (!lteRsrpField.isNull()) addString(resultList, "signal_rsrp", String.format("%d %s", lteRsrpField.intValue(), labels.getString("RESULT_SIGNAL_UNIT"))); //signal quality in LTE, RSRQ in dB final Field lteRsrqField = test.getField("lte_rsrq"); if (!lteRsrqField.isNull()) addString(resultList, "signal_rsrq", String.format("%d %s", lteRsrqField.intValue(), labels.getString("RESULT_DB_UNIT"))); // network, eg. "3G (HSPA+) //TODO fix helper-function final Field networkTypeField = test.getField("network_type"); if (!networkTypeField.isNull()) addString(resultList, "network_type", Helperfunctions.getNetworkTypeName(networkTypeField.intValue())); // geo-location JSONObject locationJson = getGeoLocation(this, test, settings, conn, labels); if (locationJson != null) { if (locationJson.has("location")) { addString(resultList, "location", locationJson.getString("location")); } if (locationJson.has("country_location")) { addString(resultList, "country_location", locationJson.getString("country_location")); } if (locationJson.has("motion")) { addString(resultList, "motion", locationJson.getString("motion")); } } // country derived from AS registry final Field countryAsnField = test.getField("country_asn"); if (!countryAsnField.isNull()) addString(resultList, "country_asn", countryAsnField.toString()); // country derived from geo-IP database final Field countryGeoipField = test.getField("country_geoip"); if (!countryGeoipField.isNull()) addString(resultList, "country_geoip", countryGeoipField.toString()); final Field zipCodeField = test.getField("zip_code"); if (!zipCodeField.isNull()) { final String zipCode = zipCodeField.toString(); final int zipCodeInt = zipCodeField.intValue(); if (zipCodeInt > 999 || zipCodeInt <= 9999) // plausibility of zip code (must be 4 digits in Austria) addString(resultList, "zip_code", zipCode); } final Field dataField = test.getField("data"); if (!Strings.isNullOrEmpty(dataField.toString())) { final JSONObject data = new JSONObject(dataField.toString()); if (data.has("region")) addString(resultList, "region", data.getString("region")); if (data.has("municipality")) addString(resultList, "municipality", data.getString("municipality")); if (data.has("settlement")) addString(resultList, "settlement", data.getString("settlement")); if (data.has("whitespace")) addString(resultList, "whitespace", data.getString("whitespace")); if (data.has("cell_id")) addString(resultList, "cell_id", data.getString("cell_id")); if (data.has("cell_name")) addString(resultList, "cell_name", data.getString("cell_name")); if (data.has("cell_id_multiple") && data.getBoolean("cell_id_multiple")) addString(resultList, "cell_id_multiple", getTranslation("value", "cell_id_multiple")); } final Field speedTestDurationField = test.getField("speed_test_duration"); if (!speedTestDurationField.isNull()) { final String speedTestDuration = format .format(speedTestDurationField.doubleValue() / 1000d); addString(resultList, "speed_test_duration", String.format("%s %s", speedTestDuration, labels.getString("RESULT_DURATION_UNIT"))); } // public client ip (private) addString(resultList, "client_public_ip", test.getField("client_public_ip")); // AS number - csv 24 addString(resultList, "client_public_ip_as", test.getField("public_ip_asn")); // name of AS addString(resultList, "client_public_ip_as_name", test.getField("public_ip_as_name")); // reverse hostname (from ip) - (private) addString(resultList, "client_public_ip_rdns", test.getField("public_ip_rdns")); // operator - derived from provider_id (only for pre-defined operators) //TODO replace provider-information by more generic information addString(resultList, "provider", test.getField("provider_id_name")); // type of client local ip (private) addString(resultList, "client_local_ip", test.getField("client_ip_local_type")); // nat-translation of client - csv 23 addString(resultList, "nat_type", test.getField("nat_type")); // wifi base station id SSID (numberic) eg 01:2c:3d.. addString(resultList, "wifi_ssid", test.getField("wifi_ssid")); // wifi base station id - BSSID (text) eg 'my hotspot' addString(resultList, "wifi_bssid", test.getField("wifi_bssid")); // nominal link speed of wifi connection in MBit/s final Field linkSpeedField = test.getField("wifi_link_speed"); if (!linkSpeedField.isNull()) addString(resultList, "wifi_link_speed", String.format("%s %s", linkSpeedField.toString(), labels.getString("RESULT_WIFI_LINK_SPEED_UNIT"))); // name of mobile network operator (eg. 'T-Mobile AT') addString(resultList, "network_operator_name", test.getField("network_operator_name")); // mobile network name derived from MCC/MNC of network, eg. '232-01' final Field networkOperatorField = test.getField("network_operator"); // mobile provider name, eg. 'Hutchison Drei' (derived from mobile_provider_id) final Field mobileProviderNameField = test.getField("mobile_provider_name"); if (mobileProviderNameField.isNull()) // eg. '248-02' addString(resultList, "network_operator", networkOperatorField); else { if (networkOperatorField.isNull()) addString(resultList, "network_operator", mobileProviderNameField); else // eg. 'Hutchison Drei (232-10)' addString(resultList, "network_operator", String.format("%s (%s)", mobileProviderNameField, networkOperatorField)); } addString(resultList, "network_sim_operator_name", test.getField("network_sim_operator_name")); final Field networkSimOperatorField = test.getField("network_sim_operator"); final Field networkSimOperatorTextField = test .getField("network_sim_operator_mcc_mnc_text"); if (networkSimOperatorTextField.isNull()) addString(resultList, "network_sim_operator", networkSimOperatorField); else addString(resultList, "network_sim_operator", String.format("%s (%s)", networkSimOperatorTextField, networkSimOperatorField)); final Field roamingTypeField = test.getField("roaming_type"); if (!roamingTypeField.isNull()) addString(resultList, "roaming", Helperfunctions.getRoamingType(labels, roamingTypeField.intValue())); final long totalDownload = test.getField("total_bytes_download").longValue(); final long totalUpload = test.getField("total_bytes_upload").longValue(); final long totalBytes = totalDownload + totalUpload; if (totalBytes > 0) { final String totalBytesString = format.format(totalBytes / (1000d * 1000d)); addString(resultList, "total_bytes", String.format("%s %s", totalBytesString, labels.getString("RESULT_TOTAL_BYTES_UNIT"))); } // interface volumes - total including control-server and pre-tests (and other tests) final long totalIfDownload = test.getField("test_if_bytes_download").longValue(); final long totalIfUpload = test.getField("test_if_bytes_upload").longValue(); // output only total of down- and upload final long totalIfBytes = totalIfDownload + totalIfUpload; if (totalIfBytes > 0) { final String totalIfBytesString = format.format(totalIfBytes / (1000d * 1000d)); addString(resultList, "total_if_bytes", String.format("%s %s", totalIfBytesString, labels.getString("RESULT_TOTAL_BYTES_UNIT"))); } // interface volumes during test // download test - volume in download direction final long testDlIfBytesDownload = test.getField("testdl_if_bytes_download").longValue(); if (testDlIfBytesDownload > 0l) { final String testDlIfBytesDownloadString = format .format(testDlIfBytesDownload / (1000d * 1000d)); addString(resultList, "testdl_if_bytes_download", String.format("%s %s", testDlIfBytesDownloadString, labels.getString("RESULT_TOTAL_BYTES_UNIT"))); } // download test - volume in upload direction final long testDlIfBytesUpload = test.getField("testdl_if_bytes_upload").longValue(); if (testDlIfBytesUpload > 0l) { final String testDlIfBytesUploadString = format .format(testDlIfBytesUpload / (1000d * 1000d)); addString(resultList, "testdl_if_bytes_upload", String.format("%s %s", testDlIfBytesUploadString, labels.getString("RESULT_TOTAL_BYTES_UNIT"))); } // upload test - volume in upload direction final long testUlIfBytesUpload = test.getField("testul_if_bytes_upload").longValue(); if (testUlIfBytesUpload > 0l) { final String testUlIfBytesUploadString = format .format(testUlIfBytesUpload / (1000d * 1000d)); addString(resultList, "testul_if_bytes_upload", String.format("%s %s", testUlIfBytesUploadString, labels.getString("RESULT_TOTAL_BYTES_UNIT"))); } // upload test - volume in download direction final long testUlIfBytesDownload = test.getField("testul_if_bytes_download").longValue(); if (testDlIfBytesDownload > 0l) { final String testUlIfBytesDownloadString = format .format(testUlIfBytesDownload / (1000d * 1000d)); addString(resultList, "testul_if_bytes_download", String.format("%s %s", testUlIfBytesDownloadString, labels.getString("RESULT_TOTAL_BYTES_UNIT"))); } //start time download-test final Field time_dl_ns = test.getField("time_dl_ns"); if (!time_dl_ns.isNull()) { addString(resultList, "time_dl", String.format("%s %s", format.format(time_dl_ns.doubleValue() / 1000000000d), //convert ns to s labels.getString("RESULT_DURATION_UNIT"))); } //duration download-test final Field duration_download_ns = test.getField("nsec_download"); if (!duration_download_ns.isNull()) { addString(resultList, "duration_dl", String.format("%s %s", format.format(duration_download_ns.doubleValue() / 1000000000d), //convert ns to s labels.getString("RESULT_DURATION_UNIT"))); } //start time upload-test final Field time_ul_ns = test.getField("time_ul_ns"); if (!time_ul_ns.isNull()) { addString(resultList, "time_ul", String.format("%s %s", format.format(time_ul_ns.doubleValue() / 1000000000d), //convert ns to s labels.getString("RESULT_DURATION_UNIT"))); } //duration upload-test final Field duration_upload_ns = test.getField("nsec_upload"); if (!duration_upload_ns.isNull()) { addString(resultList, "duration_ul", String.format("%s %s", format.format(duration_upload_ns.doubleValue() / 1000000000d), //convert ns to s labels.getString("RESULT_DURATION_UNIT"))); } if (ndt != null) { final String downloadNdt = format.format(ndt.getField("s2cspd").doubleValue()); addString(resultList, "speed_download_ndt", String.format("%s %s", downloadNdt, labels.getString("RESULT_DOWNLOAD_UNIT"))); final String uploaddNdt = format.format(ndt.getField("c2sspd").doubleValue()); addString(resultList, "speed_upload_ndt", String.format("%s %s", uploaddNdt, labels.getString("RESULT_UPLOAD_UNIT"))); // final String pingNdt = // format.format(ndt.getField("avgrtt").doubleValue()); // addString(resultList, "ping_ndt", // String.format("%s %s", pingNdt, // labels.getString("RESULT_PING_UNIT"))); } addString(resultList, "server_name", test.getField("server_name")); addString(resultList, "plattform", test.getField("plattform")); addString(resultList, "os_version", test.getField("os_version")); addString(resultList, "model", test.getField("model_fullname")); addString(resultList, "client_name", test.getField("client_name")); addString(resultList, "client_software_version", test.getField("client_software_version")); final String encryption = test.getField("encryption").toString(); if (encryption != null) { addString(resultList, "encryption", "NONE".equals(encryption) ? labels.getString("key_encryption_false") : labels.getString("key_encryption_true")); } addString(resultList, "client_version", test.getField("client_version")); addString(resultList, "duration", String.format("%d %s", test.getField("duration").intValue(), labels.getString("RESULT_DURATION_UNIT"))); // number of threads for download-test final Field num_threads = test.getField("num_threads"); if (!num_threads.isNull()) { addInt(resultList, "num_threads", num_threads); } //number of threads for upload-test final Field num_threads_ul = test.getField("num_threads_ul"); if (!num_threads_ul.isNull()) { addInt(resultList, "num_threads_ul", num_threads_ul); } //dz 2013-11-09 removed UUID from details as users might get confused by two // ids; //addString(resultList, "uuid", String.format("T%s", test.getField("uuid"))); final Field openTestUUIDField = test.getField("open_test_uuid"); if (!openTestUUIDField.isNull()) addString(resultList, "open_test_uuid", String.format("O%s", openTestUUIDField)); //number of threads for upload-test final Field tag = test.getField("tag"); if (!tag.isNull()) { addString(resultList, "tag", tag); } if (ndt != null) { addString(resultList, "ndt_details_main", ndt.getField("main")); addString(resultList, "ndt_details_stat", ndt.getField("stat")); addString(resultList, "ndt_details_diag", ndt.getField("diag")); } if (resultList.length() == 0) errorList.addError("ERROR_DB_GET_TESTRESULT_DETAIL"); answer.put("testresultdetail", resultList); } else errorList.addError("ERROR_REQUEST_TEST_RESULT_DETAIL_NO_UUID"); } else errorList.addError("ERROR_DB_CONNECTION"); } catch (final JSONException e) { errorList.addError("ERROR_REQUEST_JSON"); System.out.println("Error parsing JSDON Data " + e.toString()); } else errorList.addErrorString("Expected request is missing."); try { answer.putOpt("error", errorList.getList()); } catch (final JSONException e) { System.out.println("Error saving ErrorList: " + e.toString()); } answerString = answer.toString(); long elapsedTime = System.currentTimeMillis() - startTime; System.out.println(MessageFormat.format(labels.getString("NEW_TESTRESULT_DETAIL_SUCCESS"), clientIpRaw, Long.toString(elapsedTime))); return answerString; }
From source file:com.mirth.connect.server.controllers.DefaultConfigurationController.java
@Override public String getServerTimezone(Locale locale) { TimeZone timeZone = TimeZone.getDefault(); boolean daylight = timeZone.inDaylightTime(new Date()); // Get the short timezone display name with respect to DST String timeZoneDisplay = timeZone.getDisplayName(daylight, TimeZone.SHORT, locale); // Get the offset in hours (divide by number of milliseconds in an hour) int offset = timeZone.getOffset(System.currentTimeMillis()) / (3600000); // Get the offset display in either UTC -x or UTC +x String offsetDisplay = (offset < 0) ? String.valueOf(offset) : "+" + offset; timeZoneDisplay += " (UTC " + offsetDisplay + ")"; return timeZoneDisplay; }
From source file:com.akop.bach.parser.XboxLiveParser.java
@Override protected void initRequest(HttpUriRequest request) { super.initRequest(request); // Set the timezone cookie TimeZone tz = TimeZone.getDefault(); int utcOffsetMinutes = tz.getOffset(System.currentTimeMillis()) / (1000 * 60); BasicClientCookie cookie = new BasicClientCookie("UtcOffsetMinutes", String.valueOf(utcOffsetMinutes)); cookie.setPath("/"); cookie.setDomain(".xbox.com"); mHttpClient.getCookieStore().addCookie(cookie); }
From source file:org.apache.jena.graph.test.TestTypedLiterals.java
public void testDateTimeBug2() throws Exception { String[] timezonelist = { "GMT", "America/New_York", "America/Chicago", }; for (String timezoneid : timezonelist) { TimeZone tz = TimeZone.getTimeZone(timezoneid); String[] sampletimelist = { "03/10/2012 01:29", // 03/11/2012 DST time change at 2 am "03/11/2012 00:29", "03/11/2012 01:29", "03/11/2012 02:29", "03/11/2012 03:29", "03/11/2012 04:29", "03/12/2012 01:29", "11/03/2012 23:29", // 11/04/2012 standard time change at 2 am "11/04/2012 00:29", "11/04/2012 01:29", "11/04/2012 02:29", "11/04/2012 03:29", }; String format = "MM/dd/yyy HH:mm"; for (String tstr : sampletimelist) { Date dt = getDateFromPattern(tstr, format, timezoneid); SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss z"); df.setTimeZone(tz);/*from w w w . j av a 2 s . c o m*/ Calendar cal = Calendar.getInstance(); cal.setTimeZone(tz); cal.setTime(dt); XSDDateTime xdt = new XSDDateTime(cal); int offset = tz.getOffset(dt.getTime()) / (60 * 60 * 1000); int xhr = xdt.getHours(); int dhr = cal.get(Calendar.HOUR_OF_DAY); int dif = (xhr - dhr + offset) % 24; Assert.assertEquals("Difference between cal and xdt", 0, dif); // //System.out.println("xhr="+xhr+",dhr="+dhr+",dif="+dif); // System.out.println("" // +"tstr="+tstr // +"\tdate="+df.format(dt) // +(dif==0?"\t ":"\tX") // +" xsddt="+xdt // +"\toffset="+offset); } //System.out.println(); } }