public String[] toStringArray() { Calendar cTr1 = Calendar.getInstance(); cTr1.setTime(onTime); Calendar cTr2 = Calendar.getInstance(); cTr2.setTime(offTime); String[] a = new String[iNUM]; a[iName] = name; a[iKey] = key; a[iCode] = Util.toHex(code); a[iCmd] = basename(cmd); a[iArgs] = args; if (auto == null) { auto = false; onTime = new Date(); offTime = new Date(); } a[iAuto] = auto.toString(); if (auto) { a[iTr1] = cTr1.get(Calendar.HOUR_OF_DAY) + ":" + cTr1.get(Calendar.MINUTE); a[iTr2] = cTr2.get(Calendar.HOUR_OF_DAY) + ":" + cTr2.get(Calendar.MINUTE); } else { a[iTr1] = ""; a[iTr2] = ""; } return a; }
/** * We override setValues to compute locally everything we need * * @param idx The index of the attribute to modify. * @param value The new attribute value. */ public void setValue(int idx, Object value) { super.setValue(idx, value); if (idx == ATTR_DATE_START) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date(((Long) value).longValue())); a_year = cal.get(Calendar.YEAR); a_month = cal.get(Calendar.MONTH); a_week = cal.get(Calendar.DAY_OF_WEEK); a_day = cal.get(Calendar.DAY_OF_MONTH); a_time = cal.get(Calendar.HOUR_OF_DAY) * 3600 + cal.get(Calendar.MINUTE) * 60 + cal.get(Calendar.SECOND); } else if (idx == ATTR_DATE_END) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date(((Long) value).longValue())); b_year = cal.get(Calendar.YEAR); b_month = cal.get(Calendar.MONTH); b_week = cal.get(Calendar.DAY_OF_WEEK); b_day = cal.get(Calendar.DAY_OF_MONTH); b_time = cal.get(Calendar.HOUR_OF_DAY) * 3600 + cal.get(Calendar.MINUTE) * 60 + cal.get(Calendar.SECOND); } }
/** * 计算两个日期(不包括时间)之间相差的整月数 * * @param date1 * @param date2 * @return */ public static int getMonthDiff(Date date1, Date date2) { if (date1 == null || date2 == null) { throw new InvalidParameterException("date1 and date2 cannot be null!"); } if (date1.after(date2)) { throw new InvalidParameterException("date1 cannot be after date2!"); } Calendar calendar = Calendar.getInstance(); calendar.setTime(date1); int year1 = calendar.get(Calendar.YEAR); int month1 = calendar.get(Calendar.MONTH); int day1 = calendar.get(Calendar.DATE); calendar.setTime(date2); int year2 = calendar.get(Calendar.YEAR); int month2 = calendar.get(Calendar.MONTH); int day2 = calendar.get(Calendar.DATE); int months = 0; if (day2 >= day1) { months = month2 - month1; } else { months = month2 - month1 - 1; } return (year2 - year1) * MONTHS_IN_A_YEAR + months; }
private List<Long> getPayUsers(Calendar calendar) { List<Long> payUserIds = new ArrayList<Long>(); Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(calendar.getTime()); calendar1.set(Calendar.HOUR_OF_DAY, 0); calendar1.set(Calendar.MINUTE, 0); calendar1.set(Calendar.SECOND, 0); Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(calendar.getTime()); calendar2.set(Calendar.HOUR_OF_DAY, 23); calendar2.set(Calendar.MINUTE, 59); calendar2.set(Calendar.SECOND, 59); try { PreparedStatement pstmt = orderCon.prepareStatement( "select distinct(uid) from ordersqq where time between ? and ? and cmd=7"); pstmt.setLong(1, calendar1.getTimeInMillis()); pstmt.setLong(2, calendar2.getTimeInMillis()); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { payUserIds.add(rs.getLong(1)); } } catch (Exception e) { logger.error("", e); } return payUserIds; }
/** Returns a new Calendar object which is between start and end */ public static Calendar rand(Calendar start, Calendar end) { if (start.after(end)) { Calendar temp = start; start = end; end = temp; } long diff = end.getTime().getTime() - start.getTime().getTime(); long daysDiff = diff / (1000 * 60 * 60 * 24); int delta = rand(0, (int) daysDiff); Calendar newCal = Calendar.getInstance(); newCal.setTime(start.getTime()); newCal.setTimeZone(start.getTimeZone()); newCal.add(Calendar.DAY_OF_MONTH, delta); newCal.add(Calendar.HOUR, rand(0, 23)); newCal.add(Calendar.MINUTE, rand(0, 59)); newCal.add(Calendar.SECOND, rand(0, 59)); // check range cause we might random picked value // greater than the range. if (newCal.after(end)) { newCal.setTime(end.getTime()); newCal.setTimeZone(end.getTimeZone()); } if (newCal.before(start)) { newCal.setTime(start.getTime()); newCal.setTimeZone(start.getTimeZone()); } return newCal; }
/** * Adds the date range values to the search template. * * <pre>{@code * - _date-start * - _date-end * * }</pre> * * If there is no 'start' and 'end' request parameter, then the current day is used. A day starts * at 00:00 and ends the next day at 00:00 * * @param request The request that has been done on the search node. * @param propertiesMap The map where the key-values should be added to. */ protected void addStartEnd(SlingHttpServletRequest request, Map<String, String> propertiesMap) { try { // Default is today Calendar cStart = getDayCalendar(); Calendar cEnd = getDayCalendar(); cEnd.add(Calendar.DAY_OF_MONTH, 1); // If a parameter is specified, we try to parse it and use that one. RequestParameter startParam = request.getRequestParameter(START_DAY_PARAM); RequestParameter endParam = request.getRequestParameter(END_DAY_PARAM); if (startParam != null && endParam != null) { String start = startParam.getString("UTF-8"); String end = endParam.getString("UTF-8"); cStart.setTime(format.parse(start)); cEnd.setTime(format.parse(end)); } // Calculate the beginning and the end date. String beginning = DateUtils.iso8601jcr(cStart); String end = DateUtils.iso8601jcr(cEnd); // Add to map. propertiesMap.put("_date-start", ClientUtils.escapeQueryChars(beginning)); propertiesMap.put("_date-end", ClientUtils.escapeQueryChars(end)); } catch (UnsupportedEncodingException e) { LOGGER.error( "Caught an UnsupportedEncodingException when trying to provide properties for the calendar search templates.", e); } catch (ParseException e) { LOGGER.error( "Caught a ParseException when trying to provide properties for the calendar search templates.", e); } }
public static int daysBetween(Date start, Date end) { int answer = 0; if (start.after(end)) { Date temp = start; start = end; end = temp; } Calendar c1 = Calendar.getInstance(); c1.setTime(start); Calendar c2 = Calendar.getInstance(); c2.setTime(end); while (c1.get(Calendar.YEAR) < c2.get(Calendar.YEAR)) { int dayOfYear = c1.get(Calendar.DAY_OF_YEAR); int daysInYear = c1.getActualMaximum(Calendar.DAY_OF_YEAR); answer += daysInYear - dayOfYear + 1; c1.set(Calendar.DATE, 1); c1.set(Calendar.MONDAY, Calendar.JANUARY); c1.add(Calendar.YEAR, 1); } answer += c2.get(Calendar.DAY_OF_YEAR) - c1.get(Calendar.DAY_OF_YEAR); return answer; }
public void reset() { try { leaveStartCalendar = Calendar.getInstance(); leaveStartCalendar.setTime(app.dateFormatDefault.parse(leave.getStartDate())); leaveEndCalendar = Calendar.getInstance(); leaveEndCalendar.setTime(app.dateFormatDefault.parse(leave.getEndDate())); tempEndLeaveEndCalendar = null; if (Math.abs(leave.getDays() - 0.1) < 0.00001) tvNumDays.setText("AM"); else if (Math.abs(leave.getDays() - 0.2) < 0.00001) tvNumDays.setText("PM"); else tvNumDays.setText((int) leave.getDays() + ((leave.getDays() > 1) ? " Days" : " Day")); tvDurations.setText( app.dateFormatDefault.format(leaveStartCalendar.getTime()) + ((leave.getDays() > 1) ? " - " + app.dateFormatDefault.format(leaveEndCalendar.getTime()) : "")); tvRemDays.setText(remBalance + " Days Remaining"); tempLeaveDuration = leave.getDays(); tempRemBalance = remBalance; adapter.notifyDataSetChanged(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show(); } }
@SuppressWarnings("unchecked") @Transactional(readOnly = true) public List<RouteEntity> getRoutesByCityIds( String cityFrom, String cityTo, Date date, boolean is3days) { Query q = null; String sql = "SELECT r FROM RouteEntity r WHERE isActive = true AND (" + "(regFrom = :regFrom AND regTo = :regTo ) " + " OR (regFrom = :regFrom AND throughCities LIKE :throughTo) " + " OR (throughCities LIKE :throughFrom AND regTo = :regTo ) " + " OR (throughCities LIKE :throughFrom AND throughCities LIKE :throughTo ) )" + (is3days ? " AND (regDate BETWEEN :lowerDate AND :upperDate) " : " AND regDate = :date ") + " ORDER BY regDate, regTime"; q = em.createQuery(sql); q.setParameter("regFrom", cityFrom); q.setParameter("regTo", cityTo); if (!is3days) { q.setParameter("date", date); } else { Calendar c = Calendar.getInstance(); c.setTime(date); c.add(Calendar.DATE, -3); q.setParameter("lowerDate", c.getTime(), TemporalType.DATE); c = Calendar.getInstance(); c.setTime(date); c.add(Calendar.DATE, 3); q.setParameter("upperDate", c.getTime(), TemporalType.DATE); } q.setParameter("throughTo", "%" + cityTo + "%"); q.setParameter("throughFrom", "%" + cityFrom + "%"); return (List<RouteEntity>) q.getResultList(); }
/** Helper method to calculate the number of days to the last payment */ protected long getTotalDaysToLastPayment(Date lastPaymentDate, Date nextIncomeDueDate) { long totalDays = 0; long MILLISECS_PER_DAY = (1000 * 60 * 60 * 24); // total milliseconds in a day Calendar currentDateCalendar = Calendar.getInstance(); currentDateCalendar.setTime(kEMService.getCurrentDate()); currentDateCalendar.set(Calendar.HOUR, 0); currentDateCalendar.set(Calendar.MINUTE, 0); currentDateCalendar.set(Calendar.SECOND, 0); Calendar lastPaymentDateCalendar = Calendar.getInstance(); lastPaymentDateCalendar.setTime(lastPaymentDate); lastPaymentDateCalendar.set(Calendar.HOUR, 0); lastPaymentDateCalendar.set(Calendar.MINUTE, 0); lastPaymentDateCalendar.set(Calendar.SECOND, 0); // to take care of leap year and day light savings time. long endL = lastPaymentDateCalendar.getTimeInMillis() + lastPaymentDateCalendar .getTimeZone() .getOffset(lastPaymentDateCalendar.getTimeInMillis()); long startL = currentDateCalendar.getTimeInMillis() + currentDateCalendar.getTimeZone().getOffset(currentDateCalendar.getTimeInMillis()); return (endL - startL) / MILLISECS_PER_DAY; }
public String a(PageHours paramPageHours, Resources paramResources) { GraphQLTimeRange localGraphQLTimeRange = paramPageHours.b(); PageHours.Status localStatus = paramPageHours.a(); String str1 = a(localGraphQLTimeRange.start); String str2 = a(localGraphQLTimeRange.end); String str4; if (localStatus == PageHours.Status.OPEN) str4 = paramResources.getString(2131361836, new Object[] {str1, str2}); while (true) { return str4; Calendar localCalendar = Calendar.getInstance(a, Locale.getDefault()); localCalendar.setTime(new Date(1000L * paramPageHours.d())); int i = localCalendar.get(7); localCalendar.setTime(new Date(1000L * localGraphQLTimeRange.start)); int j = localCalendar.get(7); String str3 = localCalendar.getDisplayName(7, 2, Locale.getDefault()); int k = (7 + (j - i)) % 7; if (k == 0) { str4 = paramResources.getString(2131361837, new Object[] {str1, str2}); continue; } if (k == 1) { str4 = paramResources.getString(2131361838, new Object[] {str1, str2}); continue; } if (k < 5) { str4 = paramResources.getString(2131361839, new Object[] {str3, str1, str2}); continue; } str4 = paramResources.getString(2131361840, new Object[] {str3, str1, str2}); } }
/** * 判断两个两个时间是不是同一个月 * * @param date1 * @param date2 * @return */ public static boolean isSameMonth(Date date1, Date date2) { Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); return isSameMonth(cal1, cal2); }
/** * Method returns if user on trip * * @param tripId * @param name * @param surname * @param birthday * @return */ @Override public boolean doesPersonOnTrip(Integer tripId, String name, String surname, Date birthday) { Trip trip = manager.find(Trip.class, tripId); Set<Ticket> tickets = trip.getTickets(); Calendar cal = Calendar.getInstance(); cal.setTime(birthday); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); Person person; for (Ticket ticket : tickets) { person = ticket.getPerson(); Calendar calLocal = Calendar.getInstance(); calLocal.setTime(person.getDatebirth()); int yearLocal = calLocal.get(Calendar.YEAR); int monthLocal = calLocal.get(Calendar.MONTH); int dayLocal = calLocal.get(Calendar.DAY_OF_MONTH); if ((person.getName().equals(name)) && (person.getSurname().equals(surname)) && (year == yearLocal) && (month == monthLocal) && (day == dayLocal)) { return true; } } return false; }
private void updateUserInfo() { mUserNameView.setText(mUserInfo.getName()); mHeaderPicView.setImageUrl(mUserInfo.getProtrait(), getImageLoder()); Integer post = 0; // TODO 获取文章数 mPostsView.setText(String.valueOf(post)); Integer goods = 0; // TODO 获取赞数 mGoodsView.setText(String.valueOf(goods)); String age = new String(); try { Date birthday = new SimpleDateFormat("yyyy-MM-dd").parse(mUserInfo.getBirthday()); Calendar ca = Calendar.getInstance(); ca.setTime(birthday); int birthYear = ca.get(Calendar.YEAR); ca.setTime(new Date()); int currentYear = ca.get(Calendar.YEAR); age = String.valueOf(currentYear - birthYear); } catch (Exception e) { } mAgeView.setText(age); mCityView.setText(mUserService.loadPlaceName(mUserInfo.getCity())); mDescriptionView.setText(mUserInfo.getDescription()); mSexIconView.setImageResource(UserService.SEX_DRAWABLE_MAP.get(mUserInfo.getSex())); }
public static int getIntervalMonths(Date date1, Date date2) { int iMonth = 0; int flag = 0; try { Calendar objCalendarDate1 = Calendar.getInstance(); objCalendarDate1.setTime(date1); Calendar objCalendarDate2 = Calendar.getInstance(); objCalendarDate2.setTime(date2); if (objCalendarDate2.equals(objCalendarDate1)) return 0; if (objCalendarDate1.after(objCalendarDate2)) { Calendar temp = objCalendarDate1; objCalendarDate1 = objCalendarDate2; objCalendarDate2 = temp; } if (objCalendarDate2.get(Calendar.DAY_OF_MONTH) < objCalendarDate1.get(Calendar.DAY_OF_MONTH)) flag = 1; if (objCalendarDate2.get(Calendar.YEAR) > objCalendarDate1.get(Calendar.YEAR)) iMonth = ((objCalendarDate2.get(Calendar.YEAR) - objCalendarDate1.get(Calendar.YEAR)) * 12 + objCalendarDate2.get(Calendar.MONTH) - flag) - objCalendarDate1.get(Calendar.MONTH); else iMonth = objCalendarDate2.get(Calendar.MONTH) - objCalendarDate1.get(Calendar.MONTH) - flag; } catch (Exception e) { e.printStackTrace(); } return iMonth; }
public static Date divideTime(Date data, int n) { if (n > 0) { Calendar now = Calendar.getInstance(); now.setTime(new Date()); Calendar t = Calendar.getInstance(); t.setTime(data); Calendar r = Calendar.getInstance(); r.setTime(parseStringAsDate("yyyy/MM/dd HH:mm:ss", "1970/01/01 00:00:00")); int d = t.get(Calendar.DAY_OF_MONTH); int h = t.get(Calendar.HOUR_OF_DAY); int m = t.get(Calendar.MINUTE); int s = t.get(Calendar.SECOND); r.set(Calendar.DAY_OF_MONTH, ((int) ((float) d / n == 0F ? 1 : d / n))); r.set(Calendar.HOUR, (24 * ((d - 1) % n) + h) / n); r.set(Calendar.MINUTE, (60 * ((24 * ((d - 1) % n) + h) % n) + m) / n); r.set(Calendar.SECOND, (60 * (60 * ((24 * ((d - 1) % n) + h) % n) + m) % n) + s / n); return r.getTime(); } else { return null; } }
@Before public void setUp() { dateStart.setTime(DateUtil.parseDateTime("20140101").toDate()); dateStart.set(Calendar.HOUR_OF_DAY, 0); dateStart.set(Calendar.MINUTE, 0); dateStart.set(Calendar.SECOND, 0); dateStart.add(Calendar.HOUR, 12); dateStartLastMinute.setTime(DateUtil.parseDateTime("20140101").toDate()); dateStartLastMinute.set(Calendar.HOUR_OF_DAY, 23); dateStartLastMinute.set(Calendar.MINUTE, 59); dateStartLastMinute.set(Calendar.SECOND, 59); dateStartLastMinute.add(Calendar.HOUR, 12); // creating one list wuth 3 nonMCC accounts Account account1 = new Account(); account1.setId("123"); account1.setTopAccountId(456L); account1.setCanManageClients(false); accountList = ImmutableList.of(account1, account1, account1); storageHelper = new StorageHelper(); mockedRunnableKratu = new RunnableKratu(456L, accountList, storageHelper, dateStart.getTime(), dateEnd); MockitoAnnotations.initMocks(this); when(mockedEntitiesPersister.get(Account.class, "topAccountId", 456L)).thenReturn(accountList); storageHelper.setPersister(mockedEntitiesPersister); }
protected void eventActionSpecial(ActionEvent e) throws Throwable { if (e.getSource().equals(wbuKWZurueck)) { Calendar c = Calendar.getInstance(); c.setTime(wdfKW.getDate()); c.set(Calendar.DATE, c.get(Calendar.DATE) - 7); wdfKW.setTimestamp(new java.sql.Timestamp(c.getTimeInMillis())); } else if (e.getSource().equals(wbuNaechsteKW)) { Calendar c = Calendar.getInstance(); c.setTime(wdfKW.getDate()); c.set(Calendar.DATE, c.get(Calendar.DATE) + 7); wdfKW.setTimestamp(new java.sql.Timestamp(c.getTimeInMillis())); } else if (e.getSource().equals(wbuZeitenAbschliessen)) { DelegateFactory.getInstance() .getZeiterfassungDelegate() .zeitenAbschliessen( internalFrameZeiterfassung.getPersonalDto().getIId(), wdfKW.getTimestamp()); DialogFactory.showModalDialog( LPMain.getTextRespectUISPr("lp.info"), LPMain.getTextRespectUISPr("pers.report.wochenabschluss.zeitenabgeschlossen") + wlaKW.getText()); wbuZeitenAbschliessen.setEnabled(false); } }
/** * Get DAYS difference * * @param date1 * @param date2 * @return */ public static synchronized Integer getDifferenceBetween(Date date1, Date date2) { if (date1.after(date2)) { Date swap = date1; date1 = date2; date2 = swap; } Calendar d1 = Calendar.getInstance(); d1.setTime(date1); Calendar d2 = Calendar.getInstance(); d2.setTime(date2); int days = d2.get(java.util.Calendar.DAY_OF_YEAR) - d1.get(java.util.Calendar.DAY_OF_YEAR); int y2 = d2.get(java.util.Calendar.YEAR); if (d1.get(java.util.Calendar.YEAR) != y2) { d1 = (java.util.Calendar) d1.clone(); do { days += d1.getActualMaximum(java.util.Calendar.DAY_OF_YEAR); d1.add(java.util.Calendar.YEAR, 1); } while (d1.get(java.util.Calendar.YEAR) != y2); } return days; }
public static boolean checkDate(String date1, String date2) { Date date11 = DateUtil.str2Date(date1, "yyyy-MM-dd HH:mm:ss"); // 起始时间 Date date22 = DateUtil.str2Date(date2, "yyyy-MM-dd HH:mm:ss"); // 终止时间 Calendar scalendar = Calendar.getInstance(); scalendar.setTime(date11); // 起始时间 Calendar ecalendar = Calendar.getInstance(); ecalendar.setTime(date22); // 终止时间 Calendar calendarnow = Calendar.getInstance(); System.out.println(date11.toString()); System.out.println(date22.toString()); System.out.println(scalendar.toString()); System.out.println(ecalendar.toString()); System.out.println(calendarnow.toString()); if (calendarnow.after(scalendar) && calendarnow.before(ecalendar)) { return true; } else { return false; } }
public static boolean isSameMonth(Date current, Date date) { Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(current); c2.setTime(date); return c1.get(Calendar.MONTH) == c2.get(Calendar.MONTH); }
private void caricaPubblicazioni() { String testo = "Antichi palazzi costruiti su un'alta collina, un intreccio di viuzze e scalinate, diverse piazzette caratteristiche, un paronama incantevole, unico, l'aria salubre, fresca, questa è Colonnella." + "Le mie \"estati\" sono abruzzesi e quindi conosco bene " + "dell'Abruzzo il colore e il senso dell'estate, quando " + "dai treni che mi riportavano a casa da lontani paesi, " + "passavano per il Tronto e rivedevo le prime case coloniche " + "coi mazzi di granturco sui tetti, le spiagge libere ancora, " + "i paesi affacciati su quei loro balconi naturali di colline, " + "le più belle che io conosca."; Calendar dal = Calendar.getInstance(); dal.setTime(new Date()); dal.add(Calendar.MONTH, -1); Calendar al = Calendar.getInstance(); al.setTime(new Date()); al.add(Calendar.MONTH, 1); TipoPubblicazione tipo = tipoPubblicazioneRepository.find(new Long(4)); for (int i = 0; i < 1000; i++) { Pubblicazione pubblicazione = new Pubblicazione(); pubblicazione.setAl(al.getTime()); pubblicazione.setDal(dal.getTime()); pubblicazione.setAttivo(true); pubblicazione.setAutore("flower"); pubblicazione.setDescrizione(testo); pubblicazione.setNome("pubblicazione" + i); pubblicazione.setTitolo("pubblicazione" + i); pubblicazione.setData(new Date()); pubblicazione.setTipo(tipo); String idTitle = PageUtils.createPageId(pubblicazione.getNome()); String idFinal = testPubbId(idTitle); pubblicazione.setId(idFinal); pubblicazioniRepository.persist(pubblicazione); } }
/** * 获取两个日期之间的间隔日期 * * @author modi * @version 1.0.0 */ public static int getDaysBetween(final String beginDate, final String endDate) { try { final SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.SIMPLIFIED_CHINESE); final Date bDate = format.parse(beginDate); final Date eDate = format.parse(endDate); Calendar d1 = new GregorianCalendar(); d1.setTime(bDate); final Calendar d2 = new GregorianCalendar(); d2.setTime(eDate); if (d1.after(d2)) { return 0; } int days = d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR); final int y2 = d2.get(Calendar.YEAR); if (d1.get(Calendar.YEAR) != y2) { d1 = (Calendar) d1.clone(); do { days += d1.getActualMaximum(Calendar.DAY_OF_YEAR); // 得到当年的实际天数 d1.add(Calendar.YEAR, 1); } while (d1.get(Calendar.YEAR) != y2); } return days; } catch (ParseException e) { return 0; } }
public static List<Date[]> getDays(Date from, Date to) { List<Date[]> list = new ArrayList<Date[]>(); Date[] fromto; Calendar c = Calendar.getInstance(); c.setTime(from); Calendar cTo = Calendar.getInstance(); cTo.setTime(to); /*fromto = new Date[2]; fromto[0] = c.getTime(); fromto[1] = cTo.getTime(); list.add(fromto); return list;*/ while (c.before(cTo)) { if (c.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY || c.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) { Date lFrom = c.getTime(); Calendar lCal = Calendar.getInstance(); lCal.setTime(lFrom); lCal.add(Calendar.DAY_OF_YEAR, 2); Date lTo = lCal.getTime(); fromto = new Date[2]; fromto[0] = lFrom; fromto[1] = lTo; list.add(fromto); } c.add(Calendar.DAY_OF_YEAR, 1); } return list; }
/** Initialize the filter. */ public void initialize(Object values[]) { Calendar cal = Calendar.getInstance(); long d = System.currentTimeMillis(); super.initialize(values); cal.setTime(new Date(getLong(ATTR_DATE_START, d))); a_year = cal.get(Calendar.YEAR); a_month = cal.get(Calendar.MONTH); a_week = cal.get(Calendar.DAY_OF_WEEK); a_day = cal.get(Calendar.DAY_OF_MONTH); a_time = cal.get(Calendar.HOUR_OF_DAY) * 3600 + cal.get(Calendar.MINUTE) * 60 + cal.get(Calendar.SECOND); cal.setTime(new Date(getLong(ATTR_DATE_END, d))); b_year = cal.get(Calendar.YEAR); b_month = cal.get(Calendar.MONTH); b_week = cal.get(Calendar.DAY_OF_WEEK); b_day = cal.get(Calendar.DAY_OF_MONTH); b_time = cal.get(Calendar.HOUR_OF_DAY) * 3600 + cal.get(Calendar.MINUTE) * 60 + cal.get(Calendar.SECOND); }
/** * Method is return the academic day count. * * @param attendanceDashboardDto type AttendanceDashboardDto * @return academic days type integer * @throws AkuraAppException - The exception details that occurred when processing. */ private int getAcademicDays(AttendanceDashboardDto attendanceDashboardDto) throws AkuraAppException { Date fDate = null; Date tDate = null; int year = attendanceDashboardDto.getYear(); if (attendanceDashboardDto.getMonth() == 0) { fDate = DateUtil.getFistDayOfSelectedYearMonth(year, 1); tDate = DateUtil.getLastDayOfSelectedYearMonth(year, MONTH_DECEMBER); } else { fDate = DateUtil.getFistDayOfSelectedYearMonth(year, attendanceDashboardDto.getMonth()); tDate = DateUtil.getLastDayOfSelectedYearMonth(year, attendanceDashboardDto.getMonth()); } Calendar firstDateOfPreviousMonth = Calendar.getInstance(); Calendar lastDateOfPreviousMonth = Calendar.getInstance(); firstDateOfPreviousMonth.setTime(fDate); lastDateOfPreviousMonth.setTime(tDate); List<Holiday> holidayList = commonService.findHolidayByYear( firstDateOfPreviousMonth.getTime(), lastDateOfPreviousMonth.getTime()); return HolidayUtil.countWorkingDays( firstDateOfPreviousMonth, lastDateOfPreviousMonth, holidayList); }
/** * 计算两个日期(不包括时间)之间相差的周年数 * * @param date1 * @param date2 * @return */ public static int getYearDiff(Date date1, Date date2) { if (date1 == null || date2 == null) { throw new InvalidParameterException("date1 and date2 cannot be null!"); } if (date1.after(date2)) { throw new InvalidParameterException("date1 cannot be after date2!"); } Calendar calendar = Calendar.getInstance(); calendar.setTime(date1); int year1 = calendar.get(Calendar.YEAR); int month1 = calendar.get(Calendar.MONTH); int day1 = calendar.get(Calendar.DATE); calendar.setTime(date2); int year2 = calendar.get(Calendar.YEAR); int month2 = calendar.get(Calendar.MONTH); int day2 = calendar.get(Calendar.DATE); int result = year2 - year1; if (month2 < month1) { result--; } else if (month2 == month1 && day2 < day1) { result--; } return result; }
private void accessBusinessCheck(UploadRequestUrl requestUrl, String password) throws BusinessException { UploadRequest request = requestUrl.getUploadRequest(); if (!isValidPassword(requestUrl, password)) { throw new BusinessException( BusinessErrorCode.UPLOAD_REQUEST_URL_FORBIDDEN, "You do not have the right to get this upload request url : " + requestUrl.getUuid()); } if (!(request.getStatus().equals(UploadRequestStatus.STATUS_ENABLED) || request.getStatus().equals(UploadRequestStatus.STATUS_CLOSED))) { throw new BusinessException( BusinessErrorCode.UPLOAD_REQUEST_READONLY_MODE, "The current upload request url is not available : " + requestUrl.getUuid()); } Calendar now = GregorianCalendar.getInstance(); Calendar compare = GregorianCalendar.getInstance(); compare.setTime(request.getActivationDate()); if (now.before(compare)) { throw new BusinessException( BusinessErrorCode.UPLOAD_REQUEST_NOT_ENABLE_YET, "The current upload request url is not enable yet : " + requestUrl.getUuid()); } compare.setTime(request.getExpiryDate()); if (now.after(compare)) { throw new BusinessException( BusinessErrorCode.UPLOAD_REQUEST_NOT_ENABLE_YET, "The current upload request url is no more available now. : " + requestUrl.getUuid()); } }
public int obtenerDiasHabiles(Date fecha, Date fecha2) { Calendar calendario = Calendar.getInstance(); calendario.setTimeZone(TimeZone.getTimeZone("GMT-4:00")); calendario.setTime(fecha2); calendario.add(Calendar.DAY_OF_YEAR, +1); calendario.set(Calendar.HOUR, 0); calendario.set(Calendar.HOUR_OF_DAY, 0); calendario.set(Calendar.SECOND, 0); calendario.set(Calendar.MILLISECOND, 0); calendario.set(Calendar.MINUTE, 0); fecha2 = calendario.getTime(); calendario.setTime(fecha); String fija = formatoFecha.format(fecha2); String hoy = ""; int contador = 0; do { calendario.setTime(fecha); if (calendario.get(Calendar.DAY_OF_WEEK) != 1 && calendario.get(Calendar.DAY_OF_WEEK) != 7) contador++; calendario.add(Calendar.DAY_OF_YEAR, +1); fecha = calendario.getTime(); hoy = formatoFecha.format(fecha); } while (!hoy.equals(fija)); return contador; }
public String toString() { Calendar cTr1 = Calendar.getInstance(); cTr1.setTime(onTime); Calendar cTr2 = Calendar.getInstance(); cTr2.setTime(offTime); StringBuilder sb = new StringBuilder(); sb.append(" { "); sb.append(Util.toHex(code)); sb.append(" | "); sb.append(key); sb.append(" | "); sb.append(name); sb.append(" | "); sb.append(cmd); sb.append(" | "); sb.append(args); sb.append(" | "); sb.append(auto.toString()); if (auto) { sb.append(" | "); sb.append(cTr1.get(Calendar.HOUR_OF_DAY)); sb.append(":"); sb.append(cTr1.get(Calendar.MINUTE)); sb.append(" | "); sb.append(cTr2.get(Calendar.HOUR_OF_DAY)); sb.append(":"); sb.append(cTr2.get(Calendar.MINUTE)); } sb.append(" } "); return sb.toString(); }