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:Main.java
public static void moveToCalendarSecondTerminal(Calendar cal) { moveToCalendarMillisecond(cal, cal.getActualMaximum(Calendar.MILLISECOND)); }
From source file:is.idega.idegaweb.egov.gumbo.licenses.SetDraganotveidiValidPeriod.java
public void execute(ExecutionContext executionContext) throws Exception { final Interval period; final Calendar now = Calendar.getInstance(); now.set(Calendar.HOUR, 0);//from w w w . j ava2 s.c om now.set(Calendar.MINUTE, 0); now.set(Calendar.SECOND, 0); now.set(Calendar.MILLISECOND, 0); final Calendar mayStart = Calendar.getInstance(); mayStart.set(now.get(Calendar.YEAR), Calendar.MAY, 1, 0, 0, 0); final Calendar augEnd = Calendar.getInstance(); augEnd.set(now.get(Calendar.YEAR), Calendar.AUGUST, 31, 0, 0, 0); if (now.after(mayStart) && now.before(augEnd)) { period = new Interval(now.getTime(), augEnd.getTime()); } else { period = findNearestPeriod(now); } executionContext.setVariable("date_validityFrom", period.getFrom()); executionContext.setVariable("date_validityTo", period.getTo()); }
From source file:Main.java
/** * Given a calendar (possibly containing only a day of the year), returns the earliest possible * anniversary of the date that is equal to or after the current point in time if the date * does not contain a year, or the date converted to the local time zone (if the date contains * a year./* w w w.ja va2s .com*/ * * @param target The date we wish to convert(in the UTC time zone). * @return If date does not contain a year (year < 1900), returns the next earliest anniversary * that is after the current point in time (in the local time zone). Otherwise, returns the * adjusted Date in the local time zone. */ public static Date getNextAnnualDate(Calendar target) { final Calendar today = Calendar.getInstance(); today.setTime(new Date()); // Round the current time to the exact start of today so that when we compare // today against the target date, both dates are set to exactly 0000H. today.set(Calendar.HOUR_OF_DAY, 0); today.set(Calendar.MINUTE, 0); today.set(Calendar.SECOND, 0); today.set(Calendar.MILLISECOND, 0); final boolean isYearSet = isYearSet(target); final int targetYear = target.get(Calendar.YEAR); final int targetMonth = target.get(Calendar.MONTH); final int targetDay = target.get(Calendar.DAY_OF_MONTH); final boolean isFeb29 = (targetMonth == Calendar.FEBRUARY && targetDay == 29); final GregorianCalendar anniversary = new GregorianCalendar(); // Convert from the UTC date to the local date. Set the year to today's year if the // there is no provided year (targetYear < 1900) anniversary.set(!isYearSet ? today.get(Calendar.YEAR) : targetYear, targetMonth, targetDay); // If the anniversary's date is before the start of today and there is no year set, // increment the year by 1 so that the returned date is always equal to or greater than // today. If the day is a leap year, keep going until we get the next leap year anniversary // Otherwise if there is already a year set, simply return the exact date. if (!isYearSet) { int anniversaryYear = today.get(Calendar.YEAR); if (anniversary.before(today) || (isFeb29 && !anniversary.isLeapYear(anniversaryYear))) { // If the target date is not Feb 29, then set the anniversary to the next year. // Otherwise, keep going until we find the next leap year (this is not guaranteed // to be in 4 years time). do { anniversaryYear += 1; } while (isFeb29 && !anniversary.isLeapYear(anniversaryYear)); anniversary.set(anniversaryYear, targetMonth, targetDay); } } return anniversary.getTime(); }
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 a2 s. com*/ * @param month * @param day * * @return a populated java.sql.Date with the year, month, and day specified, and no values for hour, minute, second, * millisecond * */ public static java.sql.Date newDate(Integer year, Integer month, Integer day) { // 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."); } Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.clear(Calendar.HOUR_OF_DAY); calendar.clear(Calendar.MINUTE); calendar.clear(Calendar.SECOND); calendar.clear(Calendar.MILLISECOND); return new java.sql.Date(calendar.getTimeInMillis()); }
From source file:helper.lang.DateHelperTest.java
@Test public void testAsUtcDayCalendar() { Calendar localTime = Calendar.getInstance(TimeZone.getTimeZone("CST")); Calendar cal = DateHelper.asUtcDay(localTime); assertEquals(0, cal.get(Calendar.MILLISECOND)); assertEquals(0, cal.get(Calendar.MINUTE)); assertEquals(0, cal.get(Calendar.HOUR)); assertEquals(0, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(DateHelper.UTC_TIME_ZONE, cal.getTimeZone()); assertEquals(TimeZone.getTimeZone("CST"), localTime.getTimeZone()); assertEquals(localTime.get(Calendar.YEAR), cal.get(Calendar.YEAR)); assertEquals(localTime.get(Calendar.MONTH), cal.get(Calendar.MONTH)); assertEquals(localTime.get(Calendar.DATE), cal.get(Calendar.DATE)); }
From source file:Main.java
/** * Creates a Calendar instance for the given year, month (1-based), day * (1-based), hour, minute and second in the default time zone *///from ww w .j a va 2 s.c o m public static Calendar createDate(int year, int month, int day, int hour, int minute, int second) { Calendar date = Calendar.getInstance(); date.set(year, month - 1, day, hour, minute, second); // Months start at 0 for Calendar! date.set(Calendar.MILLISECOND, 0); return date; }
From source file:net.seratch.taskun.util.CalendarUtil.java
public static Integer getMillisecond(Calendar calendar) { Integer millisecond = calendar.get(Calendar.MILLISECOND); return millisecond; }
From source file:com.qpark.eip.core.spring.auth.LimitedAccessDataProvider.java
/** * Get a {@link Date}, where hours, minutes, seconds and milliseconds are * set to 0.//w w w .j a va 2 s .c om * * @return the {@link Date} and the corresponding log string. */ private static SimpleEntry<Date, String> getRequestDate() { Calendar gc = new GregorianCalendar(); gc.set(Calendar.HOUR_OF_DAY, 0); gc.set(Calendar.MINUTE, 0); gc.set(Calendar.SECOND, 0); gc.set(Calendar.MILLISECOND, 0); String hmss = String.format("%04d%02d%02d", gc.get(Calendar.YEAR), gc.get(Calendar.MONTH) + 1, gc.get(Calendar.DAY_OF_MONTH)); SimpleEntry<Date, String> entry = new SimpleEntry<Date, String>(gc.getTime(), hmss); return entry; }
From source file:Main.java
public static Date getDateTimeFrom(Date time, Date date) { Date iTime, iDate;/*from ww w . ja v a 2 s . c om*/ Calendar calendar = Calendar.getInstance(); if (date == null) { iTime = time; iDate = new Date(); } else { iTime = time; iDate = date; } Calendar calendarDate = Calendar.getInstance(); calendarDate.setTime(iDate); Calendar calendarTime = Calendar.getInstance(); if (iTime != null) calendarTime.setTime(iTime); if (iTime != null) { calendar.set(Calendar.MINUTE, calendarTime.get(Calendar.MINUTE)); calendar.set(Calendar.HOUR_OF_DAY, calendarTime.get(Calendar.HOUR_OF_DAY)); } else { calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); } //calendar.set(Calendar.AM_PM, calendarTime.get(Calendar.AM_PM) ); calendar.set(Calendar.DAY_OF_MONTH, calendarDate.get(Calendar.DAY_OF_MONTH)); calendar.set(Calendar.MONTH, calendarDate.get(Calendar.MONTH)); calendar.set(Calendar.YEAR, calendarDate.get(Calendar.YEAR)); Date ret = calendar.getTime(); Log.v("!!!!!!!!!! calendar=", "" + ret); return ret; }
From source file:Main.java
public static void clearCalendarMillisecond(Calendar cal) { cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND)); }