List of usage examples for java.util TimeZone getTimeZone
public static TimeZone getTimeZone(ZoneId zoneId)
From source file:TimeFormat.java
public TimeFormat() { final TimeZone utcTimeZone = TimeZone.getTimeZone("UTC"); minuteFormat.setTimeZone(utcTimeZone); hourFormat.setTimeZone(utcTimeZone); }
From source file:jp.xet.baseunits.spring.TimeZoneConverter.java
@Override public TimeZone convert(String source) { return TimeZone.getTimeZone(source); }
From source file:com.github.shredder121.testannotations.timezone.TimeZoneRule.java
@IgnoreJRERequirement //conditionally executed private static TimeZone getTimeZoneJavaTime(String id) { return TimeZone.getTimeZone(ZoneId.of(id)); }
From source file:org.mayocat.configuration.json.TimeZoneModuleTest.java
@Test public void testTimeZoneDeserialization() throws Exception { Assert.assertEquals(TimeZone.getTimeZone("Europe/Paris"), mapper.readValue("\"Europe/Paris\"", TimeZone.class)); }
From source file:studio.ui.LineChart.java
public static JFreeChart createDataset(KTableModel table) { TimeZone tz = TimeZone.getTimeZone("GMT"); XYDataset ds = null;//from ww w . jav a 2 s .co m if (table.getColumnCount() > 0) { Class klass = table.getColumnClass(0); if ((klass == K.KTimestampVector.class) || (klass == K.KTimespanVector.class) || (klass == K.KDateVector.class) || (klass == K.KTimeVector.class) || (klass == K.KMonthVector.class) || (klass == K.KMinuteVector.class) || (klass == K.KSecondVector.class) || (klass == K.KDatetimeVector.class)) { TimeSeriesCollection tsc = new TimeSeriesCollection(tz); for (int col = 1; col < table.getColumnCount(); col++) { TimeSeries series = null; try { if (klass == K.KDateVector.class) { series = new TimeSeries(table.getColumnName(col), Day.class); K.KDateVector dates = (K.KDateVector) table.getColumn(0); for (int row = 0; row < dates.getLength(); row++) { K.KDate date = (K.KDate) dates.at(row); Day day = new Day(date.toDate(), tz); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(day, ((ToDouble) o).toDouble()); } } else if (klass == K.KTimeVector.class) { series = new TimeSeries(table.getColumnName(col), Millisecond.class); K.KTimeVector times = (K.KTimeVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.KTime time = (K.KTime) times.at(row); Millisecond ms = new Millisecond(time.toTime(), tz); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(ms, ((ToDouble) o).toDouble()); } } else if (klass == K.KTimestampVector.class) { series = new TimeSeries(table.getColumnName(col), Day.class); K.KTimestampVector dates = (K.KTimestampVector) table.getColumn(0); for (int row = 0; row < dates.getLength(); row++) { K.KTimestamp date = (K.KTimestamp) dates.at(row); Day day = new Day(new java.util.Date(date.toTimestamp().getTime()), tz); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(day, ((ToDouble) o).toDouble()); } } else if (klass == K.KTimespanVector.class) { series = new TimeSeries(table.getColumnName(col), Millisecond.class); K.KTimespanVector times = (K.KTimespanVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.KTimespan time = (K.KTimespan) times.at(row); Millisecond ms = new Millisecond(time.toTime(), tz); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(ms, ((ToDouble) o).toDouble()); } } else if (klass == K.KDatetimeVector.class) { series = new TimeSeries(table.getColumnName(col), Millisecond.class); K.KDatetimeVector times = (K.KDatetimeVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.KDatetime time = (K.KDatetime) times.at(row); Millisecond ms = new Millisecond(time.toTimestamp(), tz); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(ms, ((ToDouble) o).toDouble()); } } else if (klass == K.KMonthVector.class) { series = new TimeSeries(table.getColumnName(col), Month.class); K.KMonthVector times = (K.KMonthVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.Month time = (K.Month) times.at(row); int m = time.i + 24000; int y = m / 12; m = 1 + m % 12; Month month = new Month(m, y); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(month, ((ToDouble) o).toDouble()); } } else if (klass == K.KSecondVector.class) { series = new TimeSeries(table.getColumnName(col), Second.class); K.KSecondVector times = (K.KSecondVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.Second time = (K.Second) times.at(row); Second second = new Second(time.i % 60, time.i / 60, 0, 1, 1, 2001); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(second, ((ToDouble) o).toDouble()); } } else if (klass == K.KMinuteVector.class) { series = new TimeSeries(table.getColumnName(col), Minute.class); K.KMinuteVector times = (K.KMinuteVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.Minute time = (K.Minute) times.at(row); Minute minute = new Minute(time.i % 60, time.i / 60, 1, 1, 2001); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(minute, ((ToDouble) o).toDouble()); } } } catch (SeriesException e) { System.err.println("Error adding to series"); } if (series.getItemCount() > 0) tsc.addSeries(series); } ds = tsc; } else if ((klass == K.KDoubleVector.class) || (klass == K.KFloatVector.class) || (klass == K.KShortVector.class) || (klass == K.KIntVector.class) || (klass == K.KLongVector.class)) { XYSeriesCollection xysc = new XYSeriesCollection(); for (int col = 1; col < table.getColumnCount(); col++) { XYSeries series = null; try { series = new XYSeries(table.getColumnName(col)); for (int row = 0; row < table.getRowCount(); row++) { double x = ((ToDouble) table.getValueAt(row, 0)).toDouble(); double y = ((ToDouble) table.getValueAt(row, col)).toDouble(); series.add(x, y); } } catch (SeriesException e) { System.err.println("Error adding to series"); } if (series.getItemCount() > 0) xysc.addSeries(series); } ds = xysc; } } if (ds != null) { boolean legend = false; if (ds.getSeriesCount() > 1) legend = true; if (ds instanceof XYSeriesCollection) return ChartFactory.createXYLineChart("", "", "", ds, PlotOrientation.VERTICAL, legend, true, true); else if (ds instanceof TimeSeriesCollection) return ChartFactory.createTimeSeriesChart("", "", "", ds, legend, true, true); } return null; }
From source file:es.tekniker.framework.ktek.util.Utils.java
public static Calendar getCalendarGMT() { Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone("GMT")); return c;//from w ww .j a v a 2 s. co m }
From source file:Main.java
public static Date parseXmlDate(String xmlDateStr) throws Exception { if (xmlDateStr == null || xmlDateStr.trim().length() < 1) { return null; }//www .jav a 2 s . co m SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSSZ"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.parse(xmlDateStr); }
From source file:LineChart.java
private static JFreeChart createDataset(JTable table) { TimeZone tz = TimeZone.getTimeZone("GMT"); XYDataset ds = null;//from w ww . j a v a2 s . co m if (table.getColumnCount() > 0) { Class klass = table.getColumnClass(0); if ((klass == Date.class) || (klass == Time.class) || (klass == c.Month.class) || (klass == c.Minute.class) || (klass == c.Second.class) || (klass == Timestamp.class)) { TimeSeriesCollection tsc = new TimeSeriesCollection(); for (int col = 1; col < table.getColumnCount(); col++) { TimeSeries series = null; try { if (klass == Date.class) { series = new TimeSeries(table.getColumnName(col), Day.class); for (int row = 0; row < table.getRowCount(); row++) { Date date = (Date) table.getValueAt(row, 0); Day day = new Day(date, tz); Object o = table.getValueAt(row, col); if (o instanceof Number) { ((TimeSeries) series).addOrUpdate(day, (Number) table.getValueAt(row, col)); } } } else if (klass == Time.class) { series = new TimeSeries(table.getColumnName(col), Millisecond.class); for (int row = 0; row < table.getRowCount(); row++) { Time time = (Time) table.getValueAt(row, 0); Millisecond ms = new Millisecond(time, tz); // Millisecond ms = new Millisecond(time); Object o = table.getValueAt(row, col); if (o instanceof Number) { series.addOrUpdate(ms, (Number) table.getValueAt(row, col)); } } } else if (klass == Timestamp.class) { series = new TimeSeries(table.getColumnName(col), Millisecond.class); for (int row = 0; row < table.getRowCount(); row++) { Timestamp time = (Timestamp) table.getValueAt(row, 0); Millisecond ms = new Millisecond(time, tz); Object o = table.getValueAt(row, col); if (o instanceof Number) { series.addOrUpdate(ms, (Number) table.getValueAt(row, col)); } } } else if (klass == c.Month.class) { series = new TimeSeries(table.getColumnName(col), Month.class); for (int row = 0; row < table.getRowCount(); row++) { c.Month time = (c.Month) table.getValueAt(row, 0); int m = time.i + 24000; int y = m / 12; m = 1 + m % 12; Month month = new Month(m, y); Object o = table.getValueAt(row, col); if (o instanceof Number) { series.addOrUpdate(month, (Number) table.getValueAt(row, col)); } } } else if (klass == c.Second.class) { series = new TimeSeries(table.getColumnName(col), Second.class); for (int row = 0; row < table.getRowCount(); row++) { c.Second time = (c.Second) table.getValueAt(row, 0); Second second = new Second(time.i % 60, time.i / 60, 0, 1, 1, 2001); Object o = table.getValueAt(row, col); if (o instanceof Number) { series.addOrUpdate(second, (Number) table.getValueAt(row, col)); } } } else if (klass == c.Minute.class) { series = new TimeSeries(table.getColumnName(col), Minute.class); for (int row = 0; row < table.getRowCount(); row++) { c.Minute time = (c.Minute) table.getValueAt(row, 0); Minute minute = new Minute(time.i % 60, time.i / 60, 1, 1, 2001); Object o = table.getValueAt(row, col); if (o instanceof Number) { series.addOrUpdate(minute, (Number) table.getValueAt(row, col)); } } } } catch (SeriesException e) { System.err.println("Error adding to series"); } if (series.getItemCount() > 0) tsc.addSeries(series); } ds = tsc; } else if ((klass == double.class) || (klass == int.class) || (klass == short.class) || (klass == long.class) || (klass == Time.class)) { XYSeriesCollection xysc = new XYSeriesCollection(); for (int col = 1; col < table.getColumnCount(); col++) { XYSeries series = null; try { series = new XYSeries(table.getColumnName(col)); for (int row = 0; row < table.getRowCount(); row++) { Number x = (Number) table.getValueAt(row, 0); Object y = table.getValueAt(row, col); if (y instanceof Number) { series.add(x, (Number) y); } } } catch (SeriesException e) { System.err.println("Error adding to series"); } if (series.getItemCount() > 0) xysc.addSeries(series); } ds = xysc; } } if (ds != null) { boolean legend = false; if (ds.getSeriesCount() > 1) { legend = true; } if (ds instanceof XYSeriesCollection) { return ChartFactory.createXYLineChart("", "", "", ds, PlotOrientation.VERTICAL, legend, true, true); } else if (ds instanceof TimeSeriesCollection) return ChartFactory.createTimeSeriesChart("", "", "", ds, legend, true, true); } return null; }
From source file:de.incoherent.suseconferenceclient.app.SocialWrapper.java
public static ArrayList<SocialItem> getTwitterItems(Context context, String tag, int maximum) { String twitterSearch = "http://search.twitter.com/search.json?q=" + tag; ArrayList<SocialItem> socialItems = new ArrayList<SocialItem>(); // TODO Android 2.2 thinks that "Wed, 19 Sep 2012 16:35:43 +0000" is invalid // with this formatter SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z"); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); try {//from w ww. ja va 2s .com Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.twitter_icon); JSONObject result = HTTPWrapper.get(twitterSearch); JSONArray items = result.getJSONArray("results"); int len = items.length(); if ((len > 0) && (maximum > 0) && (len > maximum)) len = maximum; for (int i = 0; i < len; i++) { JSONObject jsonItem = items.getJSONObject(i); Bitmap image = HTTPWrapper.getImage(jsonItem.getString("profile_image_url")); Date formattedDate = new Date(); try { formattedDate = formatter.parse(jsonItem.getString("created_at")); } catch (ParseException e) { Log.d("SUSEConferences", "Invalid date string: " + jsonItem.getString("created_at")); e.printStackTrace(); } String user = jsonItem.getString("from_user"); SocialItem newItem = new SocialItem(SocialItem.TWITTER, user, jsonItem.getString("text"), formattedDate, DateUtils .formatDateTime(context, formattedDate.getTime(), DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE), image, icon); String link = "http://twitter.com/" + user + "/status/" + jsonItem.getString("id_str"); newItem.setLink(link); socialItems.add(newItem); } } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SocketException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return socialItems; }
From source file:com.swiftnav.sbp.loggers.JSONLogger.java
private long utc() { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); return cal.getTimeInMillis() / 1000; }