List of usage examples for java.util Calendar set
public void set(int field, int value)
From source file:com.linuxbox.enkive.teststats.StatsMonthGrainTest.java
@BeforeClass public static void setUp() throws ParseException, GathererException { coll = TestHelper.GetTestCollection(); client = TestHelper.BuildClient();/*from ww w. j a v a 2 s .c o m*/ grain = new MonthConsolidator(client); // clean up if week was run... Map<String, Object> queryMap = new HashMap<String, Object>(); queryMap.put(CONSOLIDATION_TYPE, CONSOLIDATION_DAY); StatsQuery statsQuery = new MongoStatsQuery(null, CONSOLIDATION_DAY, null); Set<Object> ids = new HashSet<Object>(); for (Map<String, Object> mapToDelete : client.queryStatistics(statsQuery)) { ids.add(mapToDelete.get("_id")); } if (!ids.isEmpty()) { client.remove(ids); } // TODO List<Map<String, Object>> stats = (new DayConsolidator(client)).consolidateData(); Map<String, Object> timeMap = new HashMap<String, Object>(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.HOUR, 0); cal.set(Calendar.DAY_OF_MONTH, 1); for (int i = 0; i < 10; i++) { if (i == 5) { cal.add(Calendar.MONTH, -1); } timeMap.put(CONSOLIDATION_MAX, cal.getTime()); timeMap.put(CONSOLIDATION_MIN, cal.getTime()); for (Map<String, Object> data : stats) { data.put(STAT_TIMESTAMP, timeMap); } client.storeData(stats); } dataCount = coll.count(); }
From source file:com.ekom.ekomerp.global.DateTimeUtils.java
public static Date getFirstDayOfWeek(Date date, Locale locale) { Calendar calendar = getCalendarWithoutTime(date, locale); calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek()); return calendar.getTime(); }
From source file:com.ekom.ekomerp.global.DateTimeUtils.java
public static Date getSpecificDayOfWeek(Date date, int javaCalendarDayNumber, Locale locale) { Calendar calendar = getCalendarWithoutTime(date, locale); calendar.set(Calendar.DAY_OF_WEEK, javaCalendarDayNumber); return calendar.getTime(); }
From source file:com.qpark.eip.core.spring.statistics.impl.SysUserStatisticsChannelInvocationListener.java
/** * Get a {@link Date}, where hours, minutes, seconds and milliseconds are * set to 0.// ww w. j av a 2 s. co m * * @return the {@link Date} and the corresponding log string. */ public static Calendar getRequestDate() { Calendar gc = new GregorianCalendar(LOGGING_TIMEZONE); gc.set(Calendar.HOUR_OF_DAY, 0); gc.set(Calendar.MINUTE, 0); gc.set(Calendar.SECOND, 0); gc.set(Calendar.MILLISECOND, 0); return gc; }
From source file:Main.java
public static Date getNearestFutureDateWithHour(int hourOfDay) { Calendar cal = Calendar.getInstance(); int hourOfDayNow = cal.get(Calendar.HOUR_OF_DAY); if (hourOfDayNow > hourOfDay) { cal.add(Calendar.DAY_OF_MONTH, 1); }/* w w w .jav a 2 s.c om*/ cal.set(Calendar.HOUR, hourOfDay); return cal.getTime(); }
From source file:Main.java
private static void setEndOfMonthToCalendar(Calendar c) { // Get the First Day of next month so it will e considered until 0 hours // of next month int max = c.getMaximum(Calendar.DAY_OF_MONTH); c.set(Calendar.DAY_OF_MONTH, max); setEndOfDayToCalendar(c);//from ww w . j av a 2 s.c o m Log.d("La Cuenta: ", "Max of Current Month: " + DateFormat.getInstance().format(c.getTime())); }
From source file:edu.jhuapl.graphs.jfreechart.TimeSeriesEffectsTest.java
public static JFreeChartGraphSource getSource() throws GraphException { Calendar base = Calendar.getInstance(); base.set(Calendar.WEEK_OF_YEAR, 6); Random r = new Random(); List<TimePoint> ps1 = new LinkedList<TimePoint>(); List<TimePoint> ps2 = new LinkedList<TimePoint>(); List<TimePoint> ps3 = new LinkedList<TimePoint>(); for (int count = 0; count < 4; count += 1) { base.set(Calendar.DAY_OF_WEEK, 2); addPoint(base.getTime(), ps2, r); // now generate five points for ps1 and p23, the daily sets addPoint(base.getTime(), ps1, r); addPoint(base.getTime(), ps3, r, "showPoint?week=" + count + "&day=0", null); for (int i = 1; i < 5; i += 1) { base.add(Calendar.DAY_OF_WEEK, 1); addPoint(base.getTime(), ps1, r); addPoint(base.getTime(), ps3, r, "showPoint?week=" + count + "&day=" + i, null); }//from w w w .j av a2s .c o m base.set(Calendar.DAY_OF_WEEK, 1); base.add(Calendar.WEEK_OF_YEAR, 1); } List<DefaultTimeSeries> series = new LinkedList<DefaultTimeSeries>(); Map<String, Object> s1Md = new HashMap<String, Object>(); s1Md.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY); s1Md.put(GraphSource.SERIES_SHAPE, new Ellipse2D.Float(-5, -5, 10, 10)); s1Md.put(GraphSource.SERIES_TITLE, "Frederick County Counts"); series.add(new DefaultTimeSeries(ps1, s1Md)); Map<String, Object> s2Md = new HashMap<String, Object>(); s2Md.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.WEEKLY); s2Md.put(GraphSource.SERIES_SHAPE, new Ellipse2D.Float(-7, -7, 14, 14)); s2Md.put(GraphSource.SERIES_TITLE, "NCR Counts"); series.add(new DefaultTimeSeries(ps2, s2Md)); Map<String, Object> s3Md = new HashMap<String, Object>(); s3Md.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY); s3Md.put(GraphSource.SERIES_SHAPE, new Rectangle2D.Float(-3, -3, 6, 6)); s3Md.put(GraphSource.SERIES_TITLE, "Carroll County Counts"); BasicStroke bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10, new float[] { 3F, 2F, 8F }, 1F); s3Md.put(GraphSource.SERIES_STROKE, bs); series.add(new DefaultTimeSeries(ps3, s3Md)); Map<String, Object> params = new HashMap<String, Object>(); params.put(GraphSource.BACKGROUND_COLOR, Color.BLUE); params.put(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Color.WHITE); params.put(GraphSource.GRAPH_TITLE, "Counts"); params.put(GraphSource.GRAPH_X_LABEL, "Time"); params.put(GraphSource.GRAPH_Y_LABEL, "Total Counts"); DateAxis customAxis = new RotatedTickDateAxis(60.); params.put(JFreeChartTimeSeriesGraphSource.DATE_AXIS, customAxis); JFreeChartGraphSource source = new JFreeChartGraphSource(); source.setData(series); source.setParams(params); source.initialize(); return source; }
From source file:org.spring.data.gemfire.cache.UserDataStoreCacheLoader.java
protected static Calendar createCalendar(final int year, final int month, final int dayOfMonth, final int hourOfDay, final int minute, final int second) { Calendar dateTime = Calendar.getInstance(); dateTime.clear();//from w w w . ja v a 2s. co m dateTime.set(Calendar.YEAR, year); dateTime.set(Calendar.MONTH, month); dateTime.set(Calendar.DAY_OF_MONTH, dayOfMonth); dateTime.set(Calendar.HOUR_OF_DAY, dayOfMonth); dateTime.set(Calendar.MINUTE, minute); dateTime.set(Calendar.SECOND, second); return dateTime; }
From source file:de.codesourcery.eve.skills.util.Misc.java
public static Calendar stripToDay(Date d) { Calendar cal = Calendar.getInstance(); cal.setTime(d);//from w ww . ja v a2 s .c om cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal; }
From source file:com.ourlife.dev.common.utils.DateUtils.java
/** * ??/*from w ww . j av a2 s . co m*/ * * @param date * @return */ public static String[] getMonthBeginTimeAndEndTime(String date) { String[] dates = new String[2]; Calendar calendar = Calendar.getInstance(); calendar.setTime(DateUtils.parseDate(date)); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); dates[0] = DateUtils.formatDate(calendar.getTime(), "yyyy-MM-dd HH:mm:ss"); calendar.add(Calendar.MONTH, 1); dates[1] = DateUtils.formatDate(calendar.getTime(), "yyyy-MM-dd HH:mm:ss"); return dates; }