List of usage examples for java.util GregorianCalendar getTimeZone
@Override
public TimeZone getTimeZone()
From source file:Main.java
public static void main(String[] args) { GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance(); // get the time zone and print it System.out.println("Time Zone:" + cal.getTimeZone().getDisplayName()); }
From source file:Main.java
public static void main(String[] args) { GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance(); // set to another time zone cal.setTimeZone(TimeZone.getTimeZone("GMT")); System.out.println("New Time Zone:" + cal.getTimeZone().getDisplayName()); }
From source file:Main.java
/** * Oftentimes all-day events have messed up starting times, which can cause * them to be displayed before events that happen in the previous day. * * The times are usually off by the Timezone offset, so we should be able * to just subtract the offset from the given event time, and it should be * all fixed.//ww w . j a va 2 s . co m * * @param eventStart * @param eventEnd * The date to modify */ private static void fixAllDayEvent(GregorianCalendar eventStart, GregorianCalendar eventEnd) { long milliseconds = eventStart.getTimeInMillis(); milliseconds -= eventStart.getTimeZone().getRawOffset(); eventStart.setTimeInMillis(milliseconds); milliseconds = eventEnd.getTimeInMillis(); milliseconds -= eventEnd.getTimeZone().getRawOffset(); eventEnd.setTimeInMillis(milliseconds - 1000); }
From source file:fr.esrf.icat.manager.core.part.SameEntitiesMenuContribution.java
private String makeFieldFilter(final List<WrappedEntityBean> selection, final String fieldName) { final List<Object> values = new LinkedList<>(); for (WrappedEntityBean bean : selection) { try {//from w ww . j a v a2 s . co m final Object v = bean.get(fieldName); if (null != v) { values.add(v); } } catch (Exception e) { String simpleName = null; try { simpleName = bean.getEntityName(); LOG.error("Error getting field {} from {}", fieldName, simpleName, e); } catch (IllegalArgumentException e1) { LOG.error("Error getting field {} from {}: {}", fieldName, simpleName, "ERROR getting name: " + e1.getMessage(), e); } } } if (values.size() == 0) { return null; } StringBuilder b = new StringBuilder(); boolean first = true; for (Object v : values) { if (first) { first = false; } else { b.append(" OR "); } if (v instanceof String) { b.append("("); b.append(fieldName); b.append("="); b.append("'"); b.append(v); b.append("'"); b.append(")"); } else if (v instanceof Boolean) { b.append("("); b.append(fieldName); b.append("="); b.append(v.toString().toUpperCase()); b.append(")"); } else if (v instanceof XMLGregorianCalendar) { final GregorianCalendar calendar = ((XMLGregorianCalendar) v).toGregorianCalendar(); QUERY_DATE_FORMAT.setTimeZone(calendar.getTimeZone()); b.append("("); b.append(fieldName); b.append(">"); b.append("{ts "); b.append(QUERY_DATE_FORMAT.format(calendar.getTime())); b.append("}"); b.append(" AND "); b.append(fieldName); b.append("<"); b.append("{ts "); calendar.roll(Calendar.SECOND, true); b.append(QUERY_DATE_FORMAT.format(calendar.getTime())); b.append("}"); b.append(")"); } else { b.append("("); b.append(fieldName); b.append("="); b.append(v); b.append(")"); } } return b.toString(); }
From source file:net.sourceforge.eclipsetrader.yahoo.Feed.java
private void update() { // Builds the url for quotes download String host = "quote.yahoo.com"; //$NON-NLS-1$ StringBuffer url = new StringBuffer("http://" + host + "/download/javasoft.beans?symbols="); //$NON-NLS-1$ //$NON-NLS-2$ for (Iterator iter = map.values().iterator(); iter.hasNext();) url = url.append((String) iter.next() + "+"); //$NON-NLS-1$ if (url.charAt(url.length() - 1) == '+') url.deleteCharAt(url.length() - 1); url.append("&format=sl1d1t1c1ohgvbap"); //$NON-NLS-1$ log.debug(url.toString());// w w w . j ava 2 s. c o m // Read the last prices String line = ""; //$NON-NLS-1$ try { HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); BundleContext context = YahooPlugin.getDefault().getBundle().getBundleContext(); ServiceReference reference = context.getServiceReference(IProxyService.class.getName()); if (reference != null) { IProxyService proxy = (IProxyService) context.getService(reference); IProxyData data = proxy.getProxyDataForHost(host, IProxyData.HTTP_PROXY_TYPE); if (data != null) { if (data.getHost() != null) client.getHostConfiguration().setProxy(data.getHost(), data.getPort()); if (data.isRequiresAuthentication()) client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(data.getUserId(), data.getPassword())); } } HttpMethod method = new GetMethod(url.toString()); method.setFollowRedirects(true); client.executeMethod(method); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); while ((line = in.readLine()) != null) { String[] item = line.split(","); //$NON-NLS-1$ if (line.indexOf(";") != -1) //$NON-NLS-1$ item = line.split(";"); //$NON-NLS-1$ Double open = null, high = null, low = null, close = null; Quote quote = new Quote(); // 2 = Date // 3 = Time try { GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("EST"), Locale.US); //$NON-NLS-1$ usDateTimeParser.setTimeZone(c.getTimeZone()); usDateParser.setTimeZone(c.getTimeZone()); usTimeParser.setTimeZone(c.getTimeZone()); String date = stripQuotes(item[2]); if (date.indexOf("N/A") != -1) //$NON-NLS-1$ date = usDateParser.format(Calendar.getInstance().getTime()); String time = stripQuotes(item[3]); if (time.indexOf("N/A") != -1) //$NON-NLS-1$ time = usTimeParser.format(Calendar.getInstance().getTime()); c.setTime(usDateTimeParser.parse(date + " " + time)); //$NON-NLS-1$ c.setTimeZone(TimeZone.getDefault()); quote.setDate(c.getTime()); } catch (Exception e) { log.error(e.getMessage() + ": " + line); //$NON-NLS-1$ } // 1 = Last price or N/A if (item[1].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setLast(numberFormat.parse(item[1]).doubleValue()); // 4 = Change // 5 = Open if (item[5].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ open = new Double(numberFormat.parse(item[5]).doubleValue()); // 6 = Maximum if (item[6].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ high = new Double(numberFormat.parse(item[6]).doubleValue()); // 7 = Minimum if (item[7].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ low = new Double(numberFormat.parse(item[7]).doubleValue()); // 8 = Volume if (item[8].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setVolume(numberFormat.parse(item[8]).intValue()); // 9 = Bid Price if (item[9].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setBid(numberFormat.parse(item[9]).doubleValue()); // 10 = Ask Price if (item[10].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setAsk(numberFormat.parse(item[10]).doubleValue()); // 11 = Close Price if (item[11].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ close = new Double(numberFormat.parse(item[11]).doubleValue()); // 0 = Code String symbol = stripQuotes(item[0]); for (Iterator iter = map.keySet().iterator(); iter.hasNext();) { Security security = (Security) iter.next(); if (symbol.equalsIgnoreCase((String) map.get(security))) { security.setQuote(quote, open, high, low, close); } } } in.close(); } catch (Exception e) { log.error(e); } }
From source file:net.sourceforge.eclipsetrader.opentick.Feed.java
public void snapshot() { SimpleDateFormat usDateTimeParser = new SimpleDateFormat("MM/dd/yyyy h:mma"); SimpleDateFormat usDateParser = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat usTimeParser = new SimpleDateFormat("h:mma"); NumberFormat numberFormat = NumberFormat.getInstance(Locale.US); // Builds the url for quotes download String host = "quote.yahoo.com"; StringBuffer url = new StringBuffer("http://" + host + "/download/javasoft.beans?symbols="); for (Iterator iter = subscribedSecurities.iterator(); iter.hasNext();) { Security security = (Security) iter.next(); url = url.append(security.getCode() + "+"); }//from w w w . java 2 s .com if (url.charAt(url.length() - 1) == '+') url.deleteCharAt(url.length() - 1); url.append("&format=sl1d1t1c1ohgvbap"); // Read the last prices String line = ""; try { HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); BundleContext context = OpenTickPlugin.getDefault().getBundle().getBundleContext(); ServiceReference reference = context.getServiceReference(IProxyService.class.getName()); if (reference != null) { IProxyService proxy = (IProxyService) context.getService(reference); IProxyData data = proxy.getProxyDataForHost(host, IProxyData.HTTP_PROXY_TYPE); if (data != null) { if (data.getHost() != null) client.getHostConfiguration().setProxy(data.getHost(), data.getPort()); if (data.isRequiresAuthentication()) client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(data.getUserId(), data.getPassword())); } } HttpMethod method = new GetMethod(url.toString()); method.setFollowRedirects(true); client.executeMethod(method); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); while ((line = in.readLine()) != null) { String[] item = line.split(","); if (line.indexOf(";") != -1) item = line.split(";"); Double open = null, high = null, low = null, close = null; Quote quote = new Quote(); // 2 = Date // 3 = Time try { GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("EST"), Locale.US); usDateTimeParser.setTimeZone(c.getTimeZone()); usDateParser.setTimeZone(c.getTimeZone()); usTimeParser.setTimeZone(c.getTimeZone()); String date = stripQuotes(item[2]); if (date.indexOf("N/A") != -1) date = usDateParser.format(Calendar.getInstance().getTime()); String time = stripQuotes(item[3]); if (time.indexOf("N/A") != -1) time = usTimeParser.format(Calendar.getInstance().getTime()); c.setTime(usDateTimeParser.parse(date + " " + time)); c.setTimeZone(TimeZone.getDefault()); quote.setDate(c.getTime()); } catch (Exception e) { System.out.println(e.getMessage() + ": " + line); } // 1 = Last price or N/A if (item[1].equalsIgnoreCase("N/A") == false) quote.setLast(numberFormat.parse(item[1]).doubleValue()); // 4 = Change // 5 = Open if (item[5].equalsIgnoreCase("N/A") == false) open = new Double(numberFormat.parse(item[5]).doubleValue()); // 6 = Maximum if (item[6].equalsIgnoreCase("N/A") == false) high = new Double(numberFormat.parse(item[6]).doubleValue()); // 7 = Minimum if (item[7].equalsIgnoreCase("N/A") == false) low = new Double(numberFormat.parse(item[7]).doubleValue()); // 8 = Volume if (item[8].equalsIgnoreCase("N/A") == false) quote.setVolume(numberFormat.parse(item[8]).intValue()); // 9 = Bid Price if (item[9].equalsIgnoreCase("N/A") == false) quote.setBid(numberFormat.parse(item[9]).doubleValue()); // 10 = Ask Price if (item[10].equalsIgnoreCase("N/A") == false) quote.setAsk(numberFormat.parse(item[10]).doubleValue()); // 11 = Close Price if (item[11].equalsIgnoreCase("N/A") == false) close = new Double(numberFormat.parse(item[11]).doubleValue()); // 0 = Code String symbol = stripQuotes(item[0]); for (Iterator iter = subscribedSecurities.iterator(); iter.hasNext();) { Security security = (Security) iter.next(); if (symbol.equalsIgnoreCase(security.getCode())) security.setQuote(quote, open, high, low, close); } } in.close(); } catch (Exception e) { System.out.println(e.getMessage() + ": " + line); e.printStackTrace(); } }