List of usage examples for java.util Calendar MILLISECOND
int MILLISECOND
To view the source code for java.util Calendar MILLISECOND.
Click Source Link
get
and set
indicating the millisecond within the second. From source file:com.linuxbox.enkive.statistics.gathering.past.PastGatherer.java
public void consolidatePastDays() { Calendar c = Calendar.getInstance(); c.setTime(statDate);//from ww w.jav a 2 s. c o m c.set(Calendar.MILLISECOND, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.HOUR_OF_DAY, 0); setEndDate(CONSOLIDATION_DAY); if (c.getTimeInMillis() > endDate.getTime()) { client.storeData(consolidatePast(CONSOLIDATION_DAY, c)); } }
From source file:com.oic.event.RegisterProfile.java
private Date toDate(String date) throws ParseException { Date data;/*from w w w.j a v a 2 s . c om*/ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); java.util.Date d = format.parse(date); Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); data = new Date(cal.getTimeInMillis()); return data; }
From source file:com.mothsoft.alexis.engine.numeric.President2012DataSetImporter.java
@Override public void importData() { logger.info("Importing poll data"); // look back 7 days to allow for updates to polls that have ended but // not completely been tallied/finalized final GregorianCalendar afterCalendar = new GregorianCalendar(); afterCalendar.set(Calendar.HOUR_OF_DAY, 0); afterCalendar.set(Calendar.MINUTE, 0); afterCalendar.set(Calendar.MILLISECOND, 0); afterCalendar.add(Calendar.DAY_OF_MONTH, -7); final SimpleDateFormat format = new SimpleDateFormat(YYYY_MM_DD); final String after = format.format(afterCalendar.getTime()); int pageNumber = 1; Map<Date, PollResults> pollResultsByDate = new HashMap<Date, PollResults>(); Map<Date, PollResults> lastPage = getPage(after, pageNumber); while (!lastPage.isEmpty()) { // save last to map for (final Map.Entry<Date, PollResults> entry : lastPage.entrySet()) { final Date date = entry.getKey(); final PollResults pr = entry.getValue(); append(date, pr, pollResultsByDate); }/* w w w .j ava2s . c o m*/ lastPage = getPage(after, ++pageNumber); } if (!pollResultsByDate.isEmpty()) { logger.info("Deleting existing points after: " + after); deletePoints(afterCalendar.getTime()); } save(pollResultsByDate); }
From source file:ISO8601DateTimeFormat.java
/** * Parse the time zone.//from w w w. ja v a2 s. c o m * @param i The position to start parsing. * @param text The text to parse. * @return The position after parsing has finished. */ protected final int parseTZ(int i, String text) { if (i < text.length()) { // check and handle the zone/dst offset int offset = 0; if (text.charAt(i) == 'Z') { offset = 0; i++; } else { int sign = 1; if (text.charAt(i) == '-') { sign = -1; } else if (text.charAt(i) != '+') { throw new NumberFormatException(); } i++; int offsetHour = Integer.valueOf(text.substring(i, i + 2)).intValue(); i += 2; if (text.charAt(i) != ':') { throw new NumberFormatException(); } i++; int offsetMin = Integer.valueOf(text.substring(i, i + 2)).intValue(); i += 2; offset = ((offsetHour * 60) + offsetMin) * 60000 * sign; } int offsetCal = calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET); calendar.add(Calendar.MILLISECOND, offsetCal - offset); } return i; }
From source file:com.ancientprogramming.fixedformat4j.format.impl.TestFixedFormatManagerImpl.java
public void testExportIntoExistingString() { Calendar someDay = Calendar.getInstance(); someDay.set(2008, 9, 13, 0, 0, 0);//from ww w .j a va 2s.co m someDay.set(Calendar.MILLISECOND, 0); MultibleFieldsRecord multibleFieldsRecord = new MultibleFieldsRecord(); multibleFieldsRecord.setDateData(someDay.getTime()); multibleFieldsRecord.setStringData("some "); multibleFieldsRecord.setIntegerdata(100); String exportedString = manager.export("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", multibleFieldsRecord); Assert.assertEquals("wrong record exported", MULTIBLE_RECORD_DATA_X_PADDED, exportedString); }
From source file:com.evolveum.midpoint.task.quartzimpl.CleanupTest.java
private Calendar create_2013_07_12_12_00_Calendar() { Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+2")); calendar.set(Calendar.YEAR, 2013); calendar.set(Calendar.MONTH, Calendar.MAY); calendar.set(Calendar.DAY_OF_MONTH, 7); calendar.set(Calendar.HOUR_OF_DAY, 12); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar; }
From source file:org.onebusaway.webapp.actions.where.TripAction.java
private long getActualServiceDate() { TripStatusBean status = _tripDetails.getStatus(); if (status != null) return status.getServiceDate(); Calendar c = Calendar.getInstance(_timeZone); // Initial set time to noon c.set(Calendar.HOUR_OF_DAY, 12); c.set(Calendar.MINUTE, 0);/*from ww w . j a v a 2s . c o m*/ c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); // Subtract 12 hours. Usually takes you to midnight, except on DST days c.add(Calendar.HOUR_OF_DAY, -12); return c.getTimeInMillis(); }
From source file:py.una.pol.karaku.test.test.dao.interceptors.TimeInterceptorTest.java
/** * Test date time.//www. j a va 2s. c o m */ @Test public void testDateTime() { Date d = new Date(); Date d2 = new Date(d.getTime()); TimeTest tt = new TimeTest(d, d, d); this.interceptorHandler.intercept(Operation.CREATE, tt); Calendar c = Calendar.getInstance(); c.setTime(tt.getDateTime()); Calendar c2 = Calendar.getInstance(); c2.setTime(d2); assertThat(c.get(Calendar.YEAR), is(c2.get(Calendar.YEAR))); assertThat(c.get(Calendar.MONTH), is(c2.get(Calendar.MONTH))); assertThat(c.get(Calendar.DAY_OF_MONTH), is(c2.get(Calendar.DAY_OF_MONTH))); assertThat(c.get(Calendar.HOUR_OF_DAY), is(c2.get(Calendar.HOUR_OF_DAY))); assertThat(c.get(Calendar.MINUTE), is(c2.get(Calendar.MINUTE))); assertThat(c.get(Calendar.SECOND), is(0)); assertThat(c.get(Calendar.MILLISECOND), is(0)); }
From source file:com.espertech.esper.regression.pattern.TestCronParameter.java
public void testOperator() throws Exception { // Observer for last Sunday of month, 0 = Sunday int lastDayOfWeek = getLastDayOfWeekInMonth(0, 2007); calendar.set(2007, getCurrentMonth(2007), lastDayOfWeek, 8, 00, 00); printCurrentTime(calendar);/*from www. j ava 2s . c o m*/ baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, *, *, 0 last, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last day of current month calendar.set(2007, getCurrentMonth(2007), getLastDayOfMonth(2007), 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, last, *, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last day of Auguts 2007 // For Java: January=0, February=1, March=2, April=3, May=4, June=5, // July=6, August=7, September=8, November=9, October=10, December=11 // For Esper: January=1, February=2, March=3, April=4, May=5, June=6, // July=7, August=8, September=9, November=10, October=11, December=12 calendar.set(2007, Calendar.AUGUST, 31, 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, last, 8, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last day of February 2007 calendar.set(2007, Calendar.FEBRUARY, 28, 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, last, 2, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last day of week (Saturday) Calendar calendar = Calendar.getInstance(); Date date = new Date(); calendar.setTime(date); calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, *, *, last, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last Friday of June calendar.set(2007, Calendar.JUNE, 29, 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, *, 6, 5 last, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last weekday of the current month calendar.set(2007, getCurrentMonth(2007), getLastWeekDayOfMonth(null, 2007), 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, lastweekday, *, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last weekday of September 2007, it's Friday September 28th calendar.set(2007, Calendar.SEPTEMBER, 28, 10, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, lastweekday, 9, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last weekday of February, it's Wednesday February 28th calendar.set(2007, Calendar.FEBRUARY, 28, 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, lastweekday, 2, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for nearest weekday for current month on the 10th calendar.set(2007, getCurrentMonth(2007), getLastWeekDayOfMonth(10, 2007), 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, 10 weekday, *, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for nearest weekday of September 1st (Saturday), it's Monday September 3rd (no "jump" over month) calendar.set(2007, Calendar.SEPTEMBER, 3, 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, 1 weekday, 9, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for nearest weekday of September 30th (Sunday), it's Friday September 28th (no "jump" over month) calendar.set(2007, Calendar.SEPTEMBER, 28, 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, 30 weekday, 9, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last Friday of current month, // 0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4= Thursday, 5=Friday, 6=Saturday calendar.set(2007, getCurrentMonth(2007), getLastDayOfWeekInMonth(5, 2007), 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, *, *, 5 last, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); }
From source file:cn.mljia.common.notify.utils.DateUtils.java
/** * ???/* www. ja va 2s .com*/ * * @param date * 1 * @param otherDate * 2 * @param withUnit * ??Calendar field? * @return 0, 0 ??0 */ public static int compareDate(Date date, Date otherDate, int withUnit) { Calendar dateCal = Calendar.getInstance(); dateCal.setTime(date); Calendar otherDateCal = Calendar.getInstance(); otherDateCal.setTime(otherDate); switch (withUnit) { case Calendar.YEAR: dateCal.clear(Calendar.MONTH); otherDateCal.clear(Calendar.MONTH); case Calendar.MONTH: dateCal.set(Calendar.DATE, 1); otherDateCal.set(Calendar.DATE, 1); case Calendar.DATE: dateCal.set(Calendar.HOUR_OF_DAY, 0); otherDateCal.set(Calendar.HOUR_OF_DAY, 0); case Calendar.HOUR: dateCal.clear(Calendar.MINUTE); otherDateCal.clear(Calendar.MINUTE); case Calendar.MINUTE: dateCal.clear(Calendar.SECOND); otherDateCal.clear(Calendar.SECOND); case Calendar.SECOND: dateCal.clear(Calendar.MILLISECOND); otherDateCal.clear(Calendar.MILLISECOND); case Calendar.MILLISECOND: break; default: throw new IllegalArgumentException("withUnit ?? " + withUnit + " ????"); } return dateCal.compareTo(otherDateCal); }