List of usage examples for java.util Calendar add
public abstract void add(int field, int amount);
From source file:net.kamhon.ieagle.util.DateUtil.java
/** * add time to date.//from w ww . j a v a 2 s .co m * * @param date * @param time * @return */ public static Date addTime(Date date, Time time) { Calendar calendar = setTime(date); calendar.add(Calendar.SECOND, time.getSecond()); calendar.add(Calendar.MINUTE, time.getMinute()); calendar.add(Calendar.HOUR_OF_DAY, time.getHour()); return calendar.getTime(); }
From source file:com.vaadin.addon.jpacontainer.demo.TestDataGenerator.java
private static Date addDaysToDate(Date date, int days) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//from ww w . jav a 2 s.c om cal.add(Calendar.DATE, days); return cal.getTime(); }
From source file:at.newsagg.utils.ParserUtils.java
private static Date extractTimeZone(String strdate, Date thedate) { // try to extract -06:00 String tzSign = strdate.substring(strdate.length() - 6, strdate.length() - 5); String tzHour = strdate.substring(strdate.length() - 5, strdate.length() - 3); String tzMin = strdate.substring(strdate.length() - 2); if (tzSign.equals("-") || tzSign.equals("+")) { int h = Integer.parseInt(tzHour); int m = Integer.parseInt(tzMin); // NOTE: this is really plus, since perspective is from GMT if (tzSign.equals("+")) { h = -1 * h;//from w w w . j a v a 2 s .c om m = -1 * m; } Calendar cal = Calendar.getInstance(); cal.setTime(thedate); cal.add(Calendar.HOUR_OF_DAY, h); cal.add(Calendar.MINUTE, m); // calculate according the used timezone cal.add(Calendar.MILLISECOND, localTimeDiff(cal.getTimeZone(), thedate)); thedate = cal.getTime(); } return thedate; }
From source file:com.swiftcorp.portal.common.util.CalendarUtils.java
public static Calendar addDayToCalendar(Calendar calendar, int day) { calendar.add(Calendar.DAY_OF_MONTH, day); return calendar; }
From source file:com.swiftcorp.portal.common.util.CalendarUtils.java
public static Calendar addMonthToCalendar(Calendar calendar, int month) { calendar.add(Calendar.MONTH, month); return calendar; }
From source file:Main.java
/** * Add date time with one minute./*from w w w .ja v a2 s.c o m*/ * * @param listing the listing * @param currentTime the current time * @param isPast true/false if past time */ private static void addDateTimeWithOneMinute(final List<Long> listing, final long currentTime, final boolean isPast) { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currentTime); if (isPast) { calendar.add(Calendar.MINUTE, -1); } else { calendar.add(Calendar.SECOND, 62); } listing.add(calendar.getTimeInMillis()); }
From source file:Main.java
private static Calendar prepareCalendar(int hourOfDay, int minute) { Calendar calNow = Calendar.getInstance(); Calendar calSet = (Calendar) calNow.clone(); calSet.set(Calendar.HOUR_OF_DAY, hourOfDay); calSet.set(Calendar.MINUTE, minute); calSet.set(Calendar.SECOND, 0); calSet.set(Calendar.MILLISECOND, 0); if (calSet.compareTo(calNow) <= 0) { // Today Set time passed, count to tomorrow calSet.add(Calendar.DATE, 1); }/*from ww w .j a v a 2 s . c o m*/ return calSet; }
From source file:com.orange.oidc.tim.service.TokensKeys.java
static String makeExpires64(String durationExpires) { if (durationExpires != null) { try {/*from w ww .j a v a 2s .co m*/ int duration = Integer.parseInt(durationExpires); if (duration > 1) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, duration); byte[] bytes = ByteBuffer.allocate(8).putLong(cal.getTimeInMillis()).array(); return KryptoUtils.encodeB64(bytes); } } catch (Exception e) { e.printStackTrace(); } } return ""; }
From source file:models.RememberMeInfo.java
/** * ?<br>/* w w w .jav a 2 s . co m*/ * ?? ?cookie??<br> * ??? */ public static void rememberMeAutoLogin(Request request, final Response response, final Session session) { String path = request.path(); // ?tell/poll??, forgetMe?? if (StringUtils.isNotBlank(path) && (isMsgTellPollUrl(path) || path.startsWith("/forgetMe"))) { return; } // ?? ?cookie?? if (!UserAuthService.isLogin(session)) { Cookie cookie = request.cookie(Constants.COOKIE_REMEMBER_ME); if (null != cookie && StringUtils.isNotBlank(cookie.value())) { final String cookieValue = cookie.value(); JPAUtil.indieTransaction(new IndieTransactionCall() { @Override public void call(EntityManager em) { @SuppressWarnings("unchecked") List<RememberMeInfo> entityList = em.createQuery( "from RememberMeInfo rm left join fetch rm.user where rm.cookieValue = :cookieValue ") .setParameter("cookieValue", cookieValue).getResultList(); if (CollectionUtils.isNotEmpty(entityList)) { RememberMeInfo entity = entityList.get(0); User user = entity.user; Calendar expires = Calendar.getInstance(); expires.add(Calendar.SECOND, -REMEMBER_ME_EXPIRES); // ? if (entity.beginTime.before(expires.getTime())) { em.remove(entity); response.discardCookie(Constants.COOKIE_REMEMBER_ME); } else if (user.lastRMLoginTime != null && user.lastRMLoginTime.getTime() + AUTO_LOGIN_INTERVAL * 1000 > System.currentTimeMillis()) { // ? em.remove(entity); response.discardCookie(Constants.COOKIE_REMEMBER_ME); } else { // ObjectNodeResult loginObjectNodeResult = null; try { loginObjectNodeResult = User.loginByEncryptedPassword(user.getEmail(), user.getEncryptedPassword(), false, UsernameType.EMAIL); } catch (Exception e) { LOGGER.error("fail to loginByEncryptedPassword.", e); } if (null == loginObjectNodeResult || !loginObjectNodeResult.isSuccess()) { em.remove(entity); response.discardCookie(Constants.COOKIE_REMEMBER_ME); } else { User.refreshCurrentLastRMLoginTime(session); } } } else { response.discardCookie(Constants.COOKIE_REMEMBER_ME); } } }); } } }
From source file:com.inmobi.messaging.consumer.util.HadoopUtil.java
public static HadoopStreamFile getHigherFile(Path streamDirPrefix, FileSystem fs, Path databusFile) throws IOException { FileStatus stat = fs.getFileStatus(databusFile); HadoopStreamFile hs = HadoopStreamFile.create(stat); Calendar cal = Calendar.getInstance(); Date date = DatabusStreamWaitingReader.getDateFromStreamDir(streamDirPrefix, hs.getParent()); cal.setTime(date);/*from w w w . j a v a2s. c om*/ cal.add(Calendar.MINUTE, 1); return new HadoopStreamFile(DatabusStreamWaitingReader.getMinuteDirPath(streamDirPrefix, cal.getTime()), "myfile", hs.getTimestamp() + 36000); }