List of usage examples for java.util Calendar set
public void set(int field, int value)
From source file:com.linuxbox.enkive.teststats.StatsWeekGrainTest.java
@BeforeClass public static void setUp() throws ParseException, GathererException { coll = TestHelper.GetTestCollection(); client = TestHelper.BuildClient();/*ww w . j av a 2 s .c om*/ grain = new WeekConsolidator(client); List<Map<String, Object>> stats = (new DayConsolidator(client)).consolidateData(); Map<String, Object> timeMap = createMap(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.HOUR, 0); for (int i = 0; i < 10; i++) { if (i == 5) { cal.add(Calendar.WEEK_OF_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:Main.java
public static boolean isToday(long dateUtc) { final long currentTime = System.currentTimeMillis(); final Calendar calendarBefore = Calendar.getInstance(); calendarBefore.setTimeInMillis(currentTime); calendarBefore.set(Calendar.HOUR_OF_DAY, 0); calendarBefore.set(Calendar.MINUTE, 0); calendarBefore.set(Calendar.SECOND, 0); calendarBefore.set(Calendar.MILLISECOND, 0); ////w ww. ja v a 2 s . com final Calendar calendarAfter = Calendar.getInstance(); calendarAfter.setTimeInMillis(currentTime); calendarAfter.set(Calendar.HOUR_OF_DAY, 23); calendarAfter.set(Calendar.MINUTE, 59); calendarAfter.set(Calendar.SECOND, 59); calendarAfter.set(Calendar.MILLISECOND, 250); if ((dateUtc >= calendarBefore.getTimeInMillis()) && (dateUtc <= calendarAfter.getTimeInMillis())) { return true; } return false; }
From source file:Main.java
public static Date getCeilDate(Date d) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date(d.getTime() + 1000 * 60 * 60)); // Set time fields to zero cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0);/* ww w . j av a2s.co m*/ cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }
From source file:Main.java
/** * Format calendar to string/*from www .j a v a 2 s . co m*/ * @param c Calendar to convert * @param format String format of SimpleDateFormat * @return String converted */ public static String formatDate(Calendar c, String format) { if (c == null) { c = Calendar.getInstance(); c.setTimeInMillis(0); c.set(Calendar.YEAR, 1990); } return formatDate(c.getTime(), format); }
From source file:Main.java
private static final Calendar getUtcDate(Date date, boolean noYear) { final Calendar calendar = Calendar.getInstance(UTC_TIMEZONE, Locale.US); calendar.setTime(date);//from w w w . ja va 2 s. com if (noYear) { calendar.set(Calendar.YEAR, 0); } return calendar; }
From source file:Main.java
static Calendar toNearestWholeHour(Calendar d) { Calendar c = new GregorianCalendar(); c.setTime(d.getTime());/*from w w w .j av a 2 s . co m*/ if (c.get(Calendar.MINUTE) >= 30) c.add(Calendar.HOUR, 1); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); return c; }
From source file:Main.java
static Calendar toNearestWholeMinute(Calendar d) { Calendar c = new GregorianCalendar(); c.setTime(d.getTime());//from w w w .jav a2 s . c om if (c.get(Calendar.SECOND) >= 30) c.add(Calendar.MINUTE, 1); c.set(Calendar.SECOND, 0); return c; }
From source file:Main.java
/** * * This method is a utility method to create a new java.sql.Date in one line. * * @param year/*from ww w . j a v a 2 s .c om*/ * @param month * @param day * @param hour * @param minute * @param second * * @return a populated java.sql.Date with the year, month, hour, minute, and second populated, with no value for millisecond. * */ public static java.sql.Date newDate(Integer year, Integer month, Integer day, Integer hour, Integer minute, Integer second) { // test for null arguments if (year == null) { throw new IllegalArgumentException("Argument 'year' passed in was null."); } if (month == null) { throw new IllegalArgumentException("Argument 'month' passed in was null."); } if (day == null) { throw new IllegalArgumentException("Argument 'day' passed in was null."); } if (hour == null) { throw new IllegalArgumentException("Argument 'hour' passed in was null."); } if (minute == null) { throw new IllegalArgumentException("Argument 'minute' passed in was null."); } if (second == null) { throw new IllegalArgumentException("Argument 'second' passed in was null."); } Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, second); calendar.clear(Calendar.MILLISECOND); return new java.sql.Date(calendar.getTimeInMillis()); }
From source file:Main.java
public static Calendar nextMonday() { Calendar date = new GregorianCalendar(); while (date.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { date.add(Calendar.DATE, 1); }//w w w . j a v a 2 s . co m date.set(Calendar.HOUR_OF_DAY, 0); date.set(Calendar.MINUTE, 0); date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); return date; }
From source file:Main.java
public static void moveToCalendarYear(Calendar cal, int year) { assertArgumentNotZeroInteger("year", year); if (year < 0) { year++; // BC headache }/*from ww w . j a v a2 s.c o m*/ cal.set(Calendar.YEAR, year); }