Refine search
/** * Gets the last modification time of this {@code ZipEntry}. * * @return the last modification time as the number of milliseconds since * Jan. 1, 1970. */ public long getTime() { if (time != -1) { GregorianCalendar cal = new GregorianCalendar(); cal.set(Calendar.MILLISECOND, 0); cal.set(1980 + ((modDate >> 9) & 0x7f), ((modDate >> 5) & 0xf) - 1, modDate & 0x1f, (time >> 11) & 0x1f, (time >> 5) & 0x3f, (time & 0x1f) << 1); return cal.getTime().getTime(); } return -1; }
public Date calculate(int era, int year, int month, int day, int hours, int minutes, int secs, int millisecs, boolean addOneDay, TimeZone tz) { if (calendar == null) { calendar = new GregorianCalendar(tz, Locale.US); calendar.setLenient(false); calendar.setGregorianChange(new Date(Long.MIN_VALUE)); // never use Julian calendar } else { // At least on Java 6, calendar.getTimeZone is slow due to a bug, so we need lastlySetTimeZone. if (lastlySetTimeZone != tz) { // Deliberately `!=` instead of `!<...>.equals()` calendar.setTimeZone(tz); lastlySetTimeZone = tz; } } calendar.set(Calendar.ERA, era); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.set(Calendar.HOUR_OF_DAY, hours); calendar.set(Calendar.MINUTE, minutes); calendar.set(Calendar.SECOND, secs); calendar.set(Calendar.MILLISECOND, millisecs); if (addOneDay) { calendar.add(Calendar.DAY_OF_MONTH, 1); } return calendar.getTime(); }
/** * Given a start time, computes the next time when the wallclock will reach * a certain hour of the day, on a certain day of the week Eg: From today, * when is the next Saturday, 12PM ? * * @param startTime start time * @param targetDay day of the week to choose * @param targetHour hour of the day to choose * @return calendar object representing the target time */ public static GregorianCalendar getCalendarForNextRun(GregorianCalendar startTime, int targetDay, int targetHour) { long startTimeMs = startTime.getTimeInMillis(); GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(startTimeMs); // adjust time to targetHour on startDay cal.set(Calendar.HOUR_OF_DAY, targetHour); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); // check if we are past the targetHour for the current day if(cal.get(Calendar.DAY_OF_WEEK) != targetDay || cal.getTimeInMillis() < startTimeMs) { do { cal.add(Calendar.DAY_OF_YEAR, 1); } while(cal.get(Calendar.DAY_OF_WEEK) != targetDay); } return cal; }
final GregorianCalendar endCal = new GregorianCalendar(); endCal.setTime(endOfTime); try { fail(); } catch (final ArithmeticException ex) {} endCal.set(Calendar.YEAR, 280000001); try { DateUtils.truncate(endCal, Calendar.DATE); fail(); } catch (final ArithmeticException ex) {} endCal.set(Calendar.YEAR, 280000000); final Calendar cal = DateUtils.truncate(endCal, Calendar.DATE); assertEquals(0, cal.get(Calendar.HOUR));
/** * Returns the millisecond value of the specified date and time in GMT. * * @param year * the year, 0 is 1900. * @param month * the month, 0 - 11. * @param day * the day of the month, 1 - 31. * @param hour * the hour of day, 0 - 23. * @param minute * the minute of the hour, 0 - 59. * @param second * the second of the minute, 0 - 59. * @return the date and time in GMT in milliseconds. * * @deprecated Use code like this instead:<code> * Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); * cal.set(year + 1900, month, day, hour, minute, second); * cal.getTime().getTime();</code> */ @Deprecated public static long UTC(int year, int month, int day, int hour, int minute, int second) { GregorianCalendar cal = new GregorianCalendar(false); cal.setTimeZone(TimeZone.getTimeZone("GMT")); cal.set(1900 + year, month, day, hour, minute, second); return cal.getTimeInMillis(); }
@Override public Object getDecodedObject(BerInputStream in) throws IOException { GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("GMT")); c.set(Calendar.YEAR, in.times[0]); c.set(Calendar.MONTH, in.times[1]-1); c.set(Calendar.DAY_OF_MONTH, in.times[2]); c.set(Calendar.HOUR_OF_DAY, in.times[3]); c.set(Calendar.MINUTE, in.times[4]); c.set(Calendar.SECOND, in.times[5]); c.set(Calendar.MILLISECOND, in.times[6]); return c.getTime(); } }
GregorianCalendar calendar = new GregorianCalendar(getGMT()); calendar.setTimeInMillis(instant); calendar.set(Calendar.MONTH, iMonthOfYear - 1); calendar.set(Calendar.DATE, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.add(Calendar.MILLISECOND, iMillisOfDay); setDayOfMonthNext(calendar); if (calendar.getTimeInMillis() <= instant) { calendar.add(Calendar.YEAR, 1); calendar.set(Calendar.MONTH, iMonthOfYear - 1); setDayOfMonthNext(calendar); setDayOfWeek(calendar);
final GregorianCalendar endCal = new GregorianCalendar(); endCal.setTime(endOfTime); try { fail(); } catch (final ArithmeticException ex) {} endCal.set(Calendar.YEAR, 280000001); try { DateUtils.ceiling(endCal, Calendar.DATE); fail(); } catch (final ArithmeticException ex) {} endCal.set(Calendar.YEAR, 280000000); final Calendar cal = DateUtils.ceiling(endCal, Calendar.DATE); assertEquals(0, cal.get(Calendar.HOUR));
static GregorianCalendar newGreg() { GregorianCalendar retCal = new GregorianCalendar(Locale.ENGLISH); retCal.setTimeZone(new SimpleTimeZone(0, "UTC")); retCal.setLenient(false); retCal.set(Calendar.MILLISECOND, 0); return retCal; }
GregorianCalendar gc = new GregorianCalendar(); gc.set(year, month, day, hh, mm, ss); gc.setTimeZone(GMT); return gc.getTimeInMillis();
/** * Gets the last modification time of this {@code android.ZipEntry}. * * @return the last modification time as the number of milliseconds since Jan. 1, 1970. */ public long getTime() { if (time != -1) { GregorianCalendar cal = new GregorianCalendar(); cal.set(Calendar.MILLISECOND, 0); cal.set(1980 + ((modDate >> 9) & 0x7f), ((modDate >> 5) & 0xf) - 1, modDate & 0x1f, (time >> 11) & 0x1f, (time >> 5) & 0x3f, (time & 0x1f) << 1); return cal.getTime().getTime(); } return -1; }
GregorianCalendar calendar = new GregorianCalendar(getGMT()); calendar.setTimeInMillis(instant); calendar.set(Calendar.MONTH, iMonthOfYear - 1); calendar.set(Calendar.DATE, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.add(Calendar.MILLISECOND, iMillisOfDay); setDayOfMonthPrevious(calendar); if (calendar.getTimeInMillis() >= instant) { calendar.add(Calendar.YEAR, -1); calendar.set(Calendar.MONTH, iMonthOfYear - 1); setDayOfMonthPrevious(calendar); setDayOfWeek(calendar);
public long getTime() { if (time != -1) { GregorianCalendar cal = new GregorianCalendar(); cal.set(Calendar.MILLISECOND, 0); cal.set(1980 + ((modDate >> 9) & 0x7f), ((modDate >> 5) & 0xf) - 1, modDate & 0x1f, (time >> 11) & 0x1f, (time >> 5) & 0x3f, (time & 0x1f) << 1); return cal.getTime().getTime(); } return -1; }
/** * Gets the last modification time of this {@code ZipEntry}. * * @return the last modification time as the number of milliseconds since * Jan. 1, 1970. */ public long getTime() { if (time != -1) { GregorianCalendar cal = new GregorianCalendar(); cal.set(Calendar.MILLISECOND, 0); cal.set(1980 + ((modDate >> 9) & 0x7f), ((modDate >> 5) & 0xf) - 1, modDate & 0x1f, (time >> 11) & 0x1f, (time >> 5) & 0x3f, (time & 0x1f) << 1); return cal.getTime().getTime(); } return -1; }
/** * Sets the gregorian calendar hour of the day for this {@code Date} object. * * @param hour * the hour of the day. * * @deprecated Use {@code Calendar.set(Calendar.HOUR_OF_DAY, hour)} instead. */ @Deprecated public void setHours(int hour) { GregorianCalendar cal = new GregorianCalendar(milliseconds); cal.set(Calendar.HOUR_OF_DAY, hour); milliseconds = cal.getTimeInMillis(); }
/** * Sets the gregorian calendar second of the minute for this {@code Date} object. * * @param second * the seconds. * * @deprecated Use {@code Calendar.set(Calendar.SECOND, second)} instead. */ @Deprecated public void setSeconds(int second) { GregorianCalendar cal = new GregorianCalendar(milliseconds); cal.set(Calendar.SECOND, second); milliseconds = cal.getTimeInMillis(); }
/** * Sets the gregorian calendar minute of the hour for this {@code Date} object. * * @param minute * the minutes. * * @deprecated Use {@code Calendar.set(Calendar.MINUTE, minute)} instead. */ @Deprecated public void setMinutes(int minute) { GregorianCalendar cal = new GregorianCalendar(milliseconds); cal.set(Calendar.MINUTE, minute); milliseconds = cal.getTimeInMillis(); }
/** * Sets the gregorian calendar month for this {@code Date} object. * * @param month * the month. * * @deprecated Use {@code Calendar.set(Calendar.MONTH, month)} instead. */ @Deprecated public void setMonth(int month) { GregorianCalendar cal = new GregorianCalendar(milliseconds); cal.set(Calendar.MONTH, month); milliseconds = cal.getTimeInMillis(); }
/** * Sets the gregorian calendar day of the month for this {@code Date} object. * * @param day * the day of the month. * * @deprecated Use {@code Calendar.set(Calendar.DATE, day)} instead. */ @Deprecated public void setDate(int day) { GregorianCalendar cal = new GregorianCalendar(milliseconds); cal.set(Calendar.DATE, day); milliseconds = cal.getTimeInMillis(); }
/** * Sets the gregorian calendar year since 1900 for this {@code Date} object. * * @param year * the year since 1900. * * @deprecated Use {@code Calendar.set(Calendar.YEAR, year + 1900)} instead. */ @Deprecated public void setYear(int year) { GregorianCalendar cal = new GregorianCalendar(milliseconds); cal.set(Calendar.YEAR, year + 1900); milliseconds = cal.getTimeInMillis(); }