List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:com.pursuer.reader.easyrss.WebpageItemViewCtrl.java
@SuppressLint("SimpleDateFormat") private void showMobilizedPage() { showMobilized = true;/* w w w . j av a 2 s . c o m*/ view.findViewById(R.id.Mobilized).setVisibility(View.VISIBLE); view.findViewById(R.id.OriginalContent).setVisibility(View.GONE); view.findViewById(R.id.BtnMobilzedPage).setEnabled(false); view.findViewById(R.id.BtnOriginalPage).setEnabled(true); view.findViewById(R.id.OriginalProgress).setVisibility(View.GONE); view.findViewById(R.id.MobilizedProgress).setVisibility(View.VISIBLE); view.findViewById(R.id.MobilizedContent).setVisibility(View.GONE); final TextView title = (TextView) view.findViewById(R.id.ItemTitle); title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize * 4 / 3); title.setText(item.getTitle()); final TextView info = (TextView) view.findViewById(R.id.ItemInfo); info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize * 4 / 5); final StringBuilder infoText = new StringBuilder(); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); sdf.setTimeZone(TimeZone.getDefault()); infoText.append(sdf.format(Utils.timestampToDate(item.getTimestamp()))); if (item.getAuthor() != null && item.getAuthor().length() > 0) { infoText.append(" | By "); infoText.append(item.getAuthor()); } if (item.getSourceTitle() != null && item.getSourceTitle().length() > 0) { infoText.append(" ("); infoText.append(item.getSourceTitle()); infoText.append(")"); } info.setText(infoText); if (thread == null) { thread = new Thread(new Runnable() { @SuppressWarnings("deprecation") @Override public void run() { try { final StringBuilder urlBuilder = new StringBuilder(); urlBuilder.append("http://easyrss.pursuer.me/parser?url="); urlBuilder.append(URLEncoder.encode(item.getHref())); urlBuilder.append("&email="); urlBuilder.append(URLEncoder.encode(dataMgr.getSettingByName(Setting.SETTING_USERNAME))); urlBuilder.append("&version="); urlBuilder.append(context.getString(R.string.Version)); final URLConnection connection = new URL(urlBuilder.toString()).openConnection(); connection.setConnectTimeout(30 * 1000); connection.setReadTimeout(20 * 1000); final InputStreamReader input = new InputStreamReader(connection.getInputStream()); final StringBuilder builder = new StringBuilder(); final char buff[] = new char[8192]; int len; while ((len = input.read(buff)) != -1) { builder.append(new String(buff, 0, len)); } builder.append(theme == SettingTheme.THEME_NORMAL ? DataUtils.DEFAULT_NORMAL_CSS : DataUtils.DEFAULT_DARK_CSS); pageContent = builder.toString(); handler.sendMessage(handler.obtainMessage(MSG_LOADING_FINISHED, WebpageItemViewCtrl.this)); } catch (final MalformedURLException exception) { exception.printStackTrace(); pageContent = genFailedToLoadContentPage(context, theme); handler.sendMessage(handler.obtainMessage(MSG_LOADING_FINISHED, WebpageItemViewCtrl.this)); } catch (final IOException exception) { exception.printStackTrace(); pageContent = genFailedToLoadContentPage(context, theme); handler.sendMessage(handler.obtainMessage(MSG_LOADING_FINISHED, WebpageItemViewCtrl.this)); } } }); thread.setPriority(Thread.MIN_PRIORITY); thread.start(); } else if (!thread.isAlive()) { handler.sendMessage(handler.obtainMessage(MSG_LOADING_FINISHED, WebpageItemViewCtrl.this)); } }
From source file:com.jaspersoft.ji.jaxrs.dbquery.DBQueryExecutorJaxrsService.java
/** * This method removes the JasperJdbcContainer object from the cache * @param requestID//from w w w .ja va 2s . co m */ @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("/timezone") public Response getTimeZone(final @Context HttpHeaders headers) { long startTime = System.currentTimeMillis(); String result = ""; try { if (logger.isDebugEnabled()) { logger.debug("Enter getTimeZone .. Start Time" + System.currentTimeMillis()); } QueryUtil.validateRequest(headers, requestOrgCheck); result = TimeZone.getDefault().getID(); } catch (Exception ex) { logger.error(ex.getMessage(), ex); return Response.serverError().build(); } finally { if (logger.isDebugEnabled()) { long elapsedTime = System.currentTimeMillis() - startTime; logger.debug("Exit getTimeZone .. Total Time Spent: " + elapsedTime); } } return Response.status(200).entity(result).build(); }
From source file:info.magnolia.cms.core.MetaData.java
/** * Part of metadata, adds modification date of the current node *//*from www.j ava2 s.c o m*/ public void setModificationDate() throws AccessDeniedException { allowUpdate(); Calendar value = new GregorianCalendar(TimeZone.getDefault()); setProperty(this.getInternalPropertyName(LAST_MODIFIED), value); }
From source file:ch.cyberduck.core.ftp.FTPPathTest.java
@Test public void testTimestamp() { final AttributedList<Path> children = new AttributedList<Path>(); FTPPath path = (FTPPath) PathFactory.createPath( SessionFactory.createSession(new Host(Protocol.FTP, "localhost")), "/www", Path.DIRECTORY_TYPE); String[] replies = new String[] { "Type=dir;Modify=19990112033045; text" //yyyyMMddHHmmss };//from w ww . j a v a 2 s.c o m boolean success = path.parseMlsdResponse(children, Arrays.asList(replies)); assertTrue(success); assertEquals(1, children.size()); Calendar date = Calendar.getInstance(TimeZone.getDefault()); date.set(1999, Calendar.JANUARY, 12, 3, 30, 45); date.set(Calendar.MILLISECOND, 0); assertEquals(date.getTime().getTime(), children.get(0).attributes().getModificationDate()); }
From source file:com.bdb.weather.display.summary.TemperatureDeviationPlotPanel.java
public void loadData(List<SummaryRecord> list, WeatherAverages averagesCollection) { TimeSeriesCollection lowCollection = new TimeSeriesCollection(); TimeSeriesCollection meanCollection = new TimeSeriesCollection(); TimeSeriesCollection highCollection = new TimeSeriesCollection(); TimeSeries highSeries = new TimeSeries(HIGH_SERIES_NAME); TimeSeries meanSeries = new TimeSeries(MEAN_SERIES_NAME); TimeSeries lowSeries = new TimeSeries(LOW_SERIES_NAME); int n = 0;/*from w w w. ja v a 2 s . co m*/ //tableModel.setRowCount(list.size()); DateTimeFormatter dateFormat = interval.getFormat(); for (SummaryRecord record : list) { WeatherAverage averages = averagesCollection.getAverage(record.getDate()); String dateString = dateFormat.format(record.getDate()); //tableModel.setValueAt(dateString, n, DATE_COLUMN); Temperature deviation = supporter.retrieveLowOutdoorTemperature(record) .subtract(averages.getLowTemperature()); RegularTimePeriod period = RegularTimePeriod.createInstance(interval.getFreeChartClass(), TimeUtils.localDateTimeToDate(record.getDate().atStartOfDay()), TimeZone.getDefault()); TimeSeriesDataItem item = new TimeSeriesDataItem(period, deviation.get()); lowSeries.add(item); //tableModel.setValueAt(deviation, n, LOW_COLUMN); deviation = supporter.retrieveAvgOutdoorTemperature(record).subtract(averages.getMeanTemperature()); item = new TimeSeriesDataItem(period, deviation.get()); meanSeries.add(item); //tableModel.setValueAt(deviation, n, MEAN_COLUMN); deviation = supporter.retrieveHighOutdoorTemperature(record).subtract(averages.getHighTemperature()); item = new TimeSeriesDataItem(period, deviation.get()); highSeries.add(item); //tableModel.setValueAt(deviation, n, HIGH_COLUMN); n++; } lowCollection.addSeries(lowSeries); meanCollection.addSeries(meanSeries); highCollection.addSeries(highSeries); deviationPlot.setDataset(LOW_SERIES_INDEX, lowCollection); deviationPlot.setDataset(MEAN_SERIES_INDEX, meanCollection); deviationPlot.setDataset(HIGH_SERIES_INDEX, highCollection); deviationPlot.setRenderer(LOW_SERIES_INDEX, lowRenderer); deviationPlot.setRenderer(MEAN_SERIES_INDEX, meanRenderer); deviationPlot.setRenderer(HIGH_SERIES_INDEX, highRenderer); }
From source file:com.exadel.flamingo.flex.messaging.amf.io.AMF0Deserializer.java
/** * Reads date/*w w w . j a va 2 s. co m*/ * * @return * @throws IOException */ protected Date readDate() throws IOException { long ms = (long) inputStream.readDouble(); // Date in millis from 01/01/1970 // here we have to read in the raw // timezone offset (which comes in minutes, but incorrectly signed), // make it millis, and fix the sign. int timeoffset = inputStream.readShort() * 60000 * -1; // now we have millis TimeZone serverTimeZone = TimeZone.getDefault(); // now we subtract the current timezone offset and add the one that was passed // in (which is of the Flash client), which gives us the appropriate ms (i think) // -alon Calendar sent = new GregorianCalendar(); sent.setTime((new Date(ms - serverTimeZone.getRawOffset() + timeoffset))); TimeZone sentTimeZone = sent.getTimeZone(); // we have to handle daylight savings ms as well if (sentTimeZone.inDaylightTime(sent.getTime())) { // // Implementation note: we are trying to maintain compatibility // with J2SE 1.3.1 // // As such, we can't use java.util.Calendar.getDSTSavings() here // sent.setTime(new java.util.Date(sent.getTime().getTime() - 3600000)); } return sent.getTime(); }
From source file:org.jfree.data.time.HourTest.java
/** * Some checks for the getLastMillisecond() method. *///from www. j ava 2s.c o m @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Hour h = new Hour(1, 1, 1, 1970); assertEquals(3599999L, h.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:Currently.java
/** * Ignores any internal date format, and tries to show a complete * date/timp stamp in extended ISO 8601 format. UTC time (Zulu time) * or a local timezone will be used.<p> * * <table border=1>//from w w w .jav a2 s .c o m * <tr><th>zone</th><th>format</th><th>fraction</td><th>example</th></tr> * <tr><td>local</td><td>basic</td><td>integral</td><td>20020523T140427-0500</td></tr> * <tr><td>UTC</td><td>basic</td><td>integral</td><td>20020523190427Z</td></tr> * <tr><td>local</td><td>extd.</td><td>integral</td><td>2002-05-23T14:04:27-05:00</td></tr> * <tr><td>UTC</td><td>extd.</td><td>integral</td><td>2002-05-23T19:04:27Z</td></tr> * <tr><td>local</td><td>basic</td><td>millis</td><td>20020523T140427.166-0500</td></tr> * <tr><td>UTC</td><td>basic</td><td>millis</td><td>20020523190427.166Z</td></tr> * <tr><td>local</td><td>extd.</td><td>millis</td><td>2002-05-23T14:04:27.166-05:00</td></tr> * <tr><td>UTC</td><td>extd.</td><td>millis</td><td>2002-05-23T19:04:27.166Z</td></tr> * </table><p> * * @param zuluTime returns a UTC formatted stamp, if true. Otherwise * the time will be formatted according to the local zone. Local time * should be prefixed with the 'T'. * @param extendedFormat will use the extended ISO 8601 format which * separates the different timestamp items. If false, the basic * format will be used. In UTC and basic format, the 'T' separator * will be omitted. * @param withMillis will put the millisecond extension into the timestamp. * If false, the time will be without millisecond fraction. The separator * is taken from {@link java.text.DecimalFormatSymbols#getMinusSign()}, * which usually is a period or a comma. * @param now is a time stamp as Date. * @return an ISO 8601 formatted date and time representation for * the given point in time. */ public static String iso8601(boolean zuluTime, boolean extendedFormat, boolean withMillis, Date now) { Calendar c = Calendar.getInstance(zuluTime ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault()); c.setTime(now); // set up formattting options DecimalFormat nf2 = new DecimalFormat("##00"); DecimalFormat nf3 = new DecimalFormat("###000"); DecimalFormat nf4 = new DecimalFormat("####0000"); DecimalFormatSymbols dfs = nf2.getDecimalFormatSymbols(); // allocate result string buffer int size = extendedFormat ? (zuluTime ? 25 : 30) : (zuluTime ? 21 : 25); if (!withMillis) { size -= 4; } StringBuffer result = new StringBuffer(size); result.append(nf4.format(c.get(Calendar.YEAR))); if (extendedFormat) { result.append('-'); // position 5 } result.append(nf2.format(c.get(Calendar.MONTH) + 1)); if (extendedFormat) { result.append('-'); // position 8 } result.append(nf2.format(c.get(Calendar.DAY_OF_MONTH))); // generating UTC in basic format may leave out the 'T' separator if (extendedFormat || !zuluTime) { result.append('T'); // position 11 } result.append(nf2.format(c.get(Calendar.HOUR_OF_DAY))); if (extendedFormat) { result.append(':'); // position 14 } result.append(nf2.format(c.get(Calendar.MINUTE))); if (extendedFormat) { result.append(':'); // position 17 } result.append(nf2.format(c.get(Calendar.SECOND))); if (withMillis) { // Though there is no explicit spec which allows a complete // timestamp with milliseconds, it is implied through two // levels, sigh. 5.3.4.2 allows decimal fractions with // time-only stamps that have a timezone. The intro of 5.4.2 // allows 5.3.1.3. result.append(dfs.getDecimalSeparator()); // position 20 result.append(nf3.format(c.get(Calendar.MILLISECOND))); } if (zuluTime) { // this is easy result.append('Z'); } else { // time zone calculations int zone_offset = c.get(Calendar.ZONE_OFFSET) / 1000; int save_offset = c.get(Calendar.DST_OFFSET) / 1000; int diff = (zone_offset + save_offset) / 60; result.append(diff < 0 ? dfs.getMinusSign() : '+'); // position 24 if (diff < 0) { diff = Math.abs(diff); } result.append(nf2.format(diff / 60)); if (extendedFormat) { result.append(':'); } result.append(nf2.format(diff % 60)); } return result.toString(); }
From source file:com.imaginary.home.cloud.CloudTest.java
private void setupLocation() throws Exception { if (apiKeyId == null) { setupUser();/*w w w . j a va 2 s .co m*/ } HashMap<String, Object> lstate = new HashMap<String, Object>(); long key = (System.currentTimeMillis() % 100000); lstate.put("name", "My Home " + key); lstate.put("description", "Integration test location"); lstate.put("timeZone", TimeZone.getDefault().getID()); HttpClient client = getClient(); HttpPost method = new HttpPost(cloudAPI + "/location"); long timestamp = System.currentTimeMillis(); method.addHeader("Content-Type", "application/json"); method.addHeader("x-imaginary-version", VERSION); method.addHeader("x-imaginary-timestamp", String.valueOf(timestamp)); method.addHeader("x-imaginary-api-key", apiKeyId); method.addHeader("x-imaginary-signature", CloudService.sign(apiKeySecret.getBytes("utf-8"), "post:/location:" + apiKeyId + ":" + timestamp + ":" + VERSION)); //noinspection deprecation method.setEntity(new StringEntity((new JSONObject(lstate)).toString(), "application/json", "UTF-8")); HttpResponse response; StatusLine status; try { response = client.execute(method); status = response.getStatusLine(); } catch (IOException e) { e.printStackTrace(); throw new CommunicationException(e); } if (status.getStatusCode() == HttpServletResponse.SC_CREATED) { String json = EntityUtils.toString(response.getEntity()); JSONObject u = new JSONObject(json); locationId = (u.has("locationId") && !u.isNull("locationId")) ? u.getString("locationId") : null; } else { Assert.fail("Failed to create location (" + status.getStatusCode() + ": " + EntityUtils.toString(response.getEntity())); } }
From source file:StringUtils.java
/** * Converts a long timestamp to a string in the following format:</br> * YYYY[dateSeparator]MM[dateSeparator]DD[dateTimeSeparator]hh[timeSeparator]mm[timeSeparator]ss * * @param timeStamp/*from w ww . j a va 2 s . co m*/ * @param dateSeparator * @param timeSeparator * @param dateTimeSeparator * @return A String containing the formatted timestamp */ static public String formatDateTime(long timeStamp, String dateSeparator, String timeSeparator, String dateTimeSeparator) { if (dateSeparator == null) dateSeparator = ""; if (dateTimeSeparator == null) dateTimeSeparator = ""; Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getDefault()); //use system time zone cal.setTime(new Date(timeStamp)); //set the time //Format the string: StringBuffer bff = new StringBuffer(); // Date (YYYY[dateSeparator]MM[dateSeparator]DD) bff.append(StringUtils.padWithLeadingZeros(String.valueOf(cal.get(Calendar.YEAR)), 4) + dateSeparator); bff.append(StringUtils.padWithLeadingZeros(String.valueOf(cal.get(Calendar.MONTH) + 1), 2) + dateSeparator); bff.append(StringUtils.padWithLeadingZeros(String.valueOf(cal.get(Calendar.DAY_OF_MONTH)), 2)); // [dateTimeSeparator] bff.append(dateTimeSeparator); // Time (hh[timeSeparator]mm[timeSeparator]ss) bff.append(formatTime(timeStamp, timeSeparator)); //return the result return bff.toString(); }