List of usage examples for java.util Calendar HOUR_OF_DAY
int HOUR_OF_DAY
To view the source code for java.util Calendar HOUR_OF_DAY.
Click Source Link
get
and set
indicating the hour of the day. From source file:com.silverpeas.calendar.DateTimeTest.java
@Test public void createsAtASpecifiedShorterDateTime() { Calendar now = getInstance(); now.set(Calendar.SECOND, 0);/* www .j a v a 2s . c om*/ now.set(Calendar.MILLISECOND, 0); DateTime expected = new DateTime(now.getTime()); DateTime actual = DateTime.dateTimeAt(now.get((Calendar.YEAR)), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE)); assertEquals(expected.getTime(), actual.getTime(), 100); }
From source file:com.charts.FiveDayChart.java
public FiveDayChart(YStockQuote currentStock) { TimeSeries series = new TimeSeries(currentStock.get_name()); ArrayList<String> fiveDayData = currentStock.get_five_day_data(); int length = fiveDayData.size(); for (int i = 22; i < length; i += 5) { String[] data = fiveDayData.get(i).split(","); Date time = new Date((long) Integer.parseInt(data[0]) * 1000); DateFormat df = new SimpleDateFormat("MM-dd-yyyy-h-m"); series.addOrUpdate(new Minute(time), Double.parseDouble(data[1])); }//ww w . j ava 2 s .c o m String[] data = fiveDayData.get(length - 1).split(","); Date time = new Date((long) Integer.parseInt(data[0]) * 1000); DateFormat df = new SimpleDateFormat("MM-dd-yyyy-h-m"); series.addOrUpdate(new Minute(time), Double.parseDouble(data[1])); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createTimeSeriesChart( currentStock.get_name() + "(" + currentStock.get_symbol() + ")" + " Five Day", "Date", "Price", dataset, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); Date now = new Date(); SegmentedTimeline segmentedTimeline = SegmentedTimeline.newFifteenMinuteTimeline(); segmentedTimeline.addBaseTimelineExclusions(segmentedTimeline.getStartTime(), now.getTime()); Calendar[][] holidays = DayRange.getHolidayDates(); for (int i = 0; i < holidays[0].length; i++) { Calendar day = Calendar.getInstance(); day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR)); day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH)); day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH)); day.set(Calendar.HOUR_OF_DAY, 9); segmentedTimeline.addException(day.getTimeInMillis(), day.getTimeInMillis() + 21600000); } xAxis.setTimeline(segmentedTimeline); xAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //xAxis.setVerticalTickLabels(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MM-dd")); xAxis.setAutoTickUnitSelection(false); xAxis.setAutoRange(false); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage5 = MovingAverage.createMovingAverage(series, "MA(5)", 30, 0); Double currMA5 = (Double) movingAverage5.getDataItem(movingAverage5.getItemCount() - 1).getValue(); currMA5 = Math.round(currMA5 * 100.0) / 100.0; movingAverage5.setKey("MA(5): " + currMA5); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage5); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); plot.setBackgroundPaint(Color.WHITE); chartPanel = new ChartPanel(chart); chart.setBackgroundPaint(chartPanel.getBackground()); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); chartPanel.setVisible(true); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:com.projity.util.DateTime.java
public static void setCalendar(int year, int month, int day, Calendar cal) { cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0);//from w ww. j av a2 s. c o m cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); }
From source file:com.mycompany.craftdemo.utility.java
public static boolean isValidTime() { Calendar calendar = Calendar.getInstance(); TimeZone fromTimeZone = calendar.getTimeZone(); TimeZone toTimeZone = TimeZone.getTimeZone("EST"); calendar.setTimeZone(fromTimeZone);// w ww. j a va 2 s.com calendar.add(Calendar.MILLISECOND, fromTimeZone.getRawOffset() * -1); if (fromTimeZone.inDaylightTime(calendar.getTime())) { calendar.add(Calendar.MILLISECOND, calendar.getTimeZone().getDSTSavings() * -1); } calendar.add(Calendar.MILLISECOND, toTimeZone.getRawOffset()); if (toTimeZone.inDaylightTime(calendar.getTime())) { calendar.add(Calendar.MILLISECOND, toTimeZone.getDSTSavings()); } int hour = calendar.get(Calendar.HOUR_OF_DAY); return hour >= 9 && hour <= 16; }
From source file:net.netheos.pcsapi.providers.hubic.SwiftTest.java
@Test public void testParseLastModified() { // Check we won't break if a header is missing : JSONObject json = new JSONObject(); Date timestamp = Swift.parseLastModified(json); assertNull(timestamp);//from w w w . j av a2s.c o m json.put("last_modified", "2014-02-12T16:13:49.346540"); // this is UTC timestamp = Swift.parseLastModified(json); assertNotNull(timestamp); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); cal.setTime(timestamp); assertEquals(2014, cal.get(Calendar.YEAR)); assertEquals(Calendar.FEBRUARY, cal.get(Calendar.MONTH)); assertEquals(12, cal.get(Calendar.DAY_OF_MONTH)); assertEquals(16, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(13, cal.get(Calendar.MINUTE)); assertEquals(49, cal.get(Calendar.SECOND)); assertEquals(346, cal.get(Calendar.MILLISECOND)); checkLastModified("2014-02-12T16:13:49.346540", cal.getTime()); checkLastModified("2014-02-12T16:13:49.3460", cal.getTime()); checkLastModified("2014-02-12T16:13:49.346", cal.getTime()); cal.set(Calendar.MILLISECOND, 340); checkLastModified("2014-02-12T16:13:49.34", cal.getTime()); cal.set(Calendar.MILLISECOND, 300); checkLastModified("2014-02-12T16:13:49.3", cal.getTime()); cal.set(Calendar.MILLISECOND, 0); checkLastModified("2014-02-12T16:13:49.", cal.getTime()); checkLastModified("2014-02-12T16:13:49", cal.getTime()); }
From source file:com.autentia.intra.bean.holiday.HolidayBean.java
/** * List holidays. Order depends on Faces parameter sort. * * @return the list of all holidays sorted by requested criterion */// w w w .j a va 2s.c om public List<Holiday> getAll() { if (selectedYear != null) { Calendar calMin = Calendar.getInstance(); calMin.setTime(selectedYear); calMin.set(Calendar.MONTH, calMin.getMinimum(Calendar.MONTH)); calMin.set(Calendar.DAY_OF_MONTH, calMin.getMinimum(Calendar.DAY_OF_MONTH)); calMin.set(Calendar.HOUR_OF_DAY, calMin.getMinimum(Calendar.HOUR_OF_DAY)); calMin.set(Calendar.MINUTE, calMin.getMinimum(Calendar.MINUTE)); calMin.set(Calendar.SECOND, calMin.getMinimum(Calendar.SECOND)); calMin.set(Calendar.MILLISECOND, calMin.getMinimum(Calendar.MILLISECOND)); Calendar calMax = Calendar.getInstance(); calMax.setTime(selectedYear); calMax.set(Calendar.MONTH, calMax.getMaximum(Calendar.MONTH)); calMax.set(Calendar.DAY_OF_MONTH, calMax.getMaximum(Calendar.DAY_OF_MONTH)); calMax.set(Calendar.HOUR_OF_DAY, calMax.getMaximum(Calendar.HOUR_OF_DAY)); calMax.set(Calendar.MINUTE, calMax.getMaximum(Calendar.MINUTE)); calMax.set(Calendar.SECOND, calMax.getMaximum(Calendar.SECOND)); calMax.set(Calendar.MILLISECOND, calMax.getMaximum(Calendar.MILLISECOND)); setSearchStartDate(calMin.getTime()); setSearchStartDateValid(true); setSearchEndDate(calMax.getTime()); setSearchEndDateValid(true); } return manager.getAllEntities(search, new SortCriteria(sortColumn, sortAscending)); }
From source file:no.met.jtimeseries.chart.Utility.java
public static int getHourOfDayUTC(Date time) { Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.setTime(time);/*from w w w . j a v a 2s. c o m*/ return calendar.get(Calendar.HOUR_OF_DAY); }
From source file:Time.java
public int getHours() { return calendar_.get(Calendar.HOUR_OF_DAY); }