List of usage examples for java.util Calendar add
public abstract void add(int field, int amount);
From source file:com.b5m.user.frame.util.DateUtils.java
/** * ? ? ? daycount /*from ww w . j a v a 2 s. c o m*/ * @param daycount * @return */ public static String getBeforeOrAfterDay(int daycount) { Date dayBefore = new Date(); if (daycount != 0) { Calendar calendar = Calendar.getInstance(); // calendar.setTime(new Date());//? calendar.add(Calendar.DAY_OF_MONTH, daycount); // ? + dayCount dayBefore = calendar.getTime(); //? + dayCount } return Date2String(dayBefore); }
From source file:com.silverpeas.jcrutil.RandomGenerator.java
public static Calendar getCalendarAfter(Calendar date) { Calendar endDate = Calendar.getInstance(); endDate.setTimeInMillis(date.getTimeInMillis()); endDate.add(Calendar.DAY_OF_MONTH, 1 + random.nextInt(10)); return endDate; }
From source file:com.inmobi.messaging.consumer.util.HadoopUtil.java
public static void setupHadoopCluster(Configuration conf, String[] files, String[] suffixDirs, Path[] finalFiles, Path finalDir, boolean withEmptyFiles, boolean createFilesInNextHour) throws Exception { FileSystem fs = finalDir.getFileSystem(conf); Path rootDir = finalDir.getParent(); fs.delete(rootDir, true);// w w w. j av a 2 s . c o m Path tmpDataDir = new Path(rootDir, "data"); fs.mkdirs(tmpDataDir); if (!createFilesInNextHour) { setUpHadoopFiles(finalDir, conf, files, suffixDirs, finalFiles, withEmptyFiles, null, 0, 0); } else { // start from 1 hour back as we need files in two diff hours. Calendar cal = Calendar.getInstance(); cal.setTime(startCommitTime); cal.add(Calendar.HOUR_OF_DAY, -1); setUpHadoopFiles(finalDir, conf, files, suffixDirs, finalFiles, withEmptyFiles, cal.getTime(), 0, 0); // go to next hour cal.add(Calendar.HOUR_OF_DAY, 1); int index = files.length; // find number of non empty(i.e. data) files in 1 hour int numberOfNonEmptyFiles = withEmptyFiles ? (int) Math.ceil(index / 2.0) : index; int startIndex = numberOfNonEmptyFiles * 100; setUpHadoopFiles(finalDir, conf, files, suffixDirs, finalFiles, withEmptyFiles, cal.getTime(), index, startIndex); } }
From source file:DateUtils.java
/** * <p>Checks if a calendar date is after today and within a number of days in the future.</p> * @param cal the calendar, not altered, not null * @param days the number of days.//ww w .j a va2s .c om * @return true if the calendar date day is after today and within days in the future . * @throws IllegalArgumentException if the calendar is <code>null</code> */ public static boolean isWithinDaysFuture(Calendar cal, int days) { if (cal == null) { throw new IllegalArgumentException("The date must not be null"); } Calendar today = Calendar.getInstance(); Calendar future = Calendar.getInstance(); future.add(Calendar.DAY_OF_YEAR, days); return (isAfterDay(cal, today) && !isAfterDay(cal, future)); }
From source file:com.silverpeas.jcrutil.RandomGenerator.java
public static Calendar getCalendarBefore(Calendar date) { Calendar beforeDate = Calendar.getInstance(); beforeDate.setTimeInMillis(date.getTimeInMillis()); beforeDate.add(Calendar.DAY_OF_MONTH, -1 - random.nextInt(10)); return beforeDate; }
From source file:Main.java
public static List<String> getWeekDate() { List<String> list = new ArrayList<String>(); Calendar calendar = Calendar.getInstance(Locale.CHINA); calendar.setTime(new Date()); calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); list.add(calendar.get(Calendar.MONTH) + 1 + "." + calendar.get(Calendar.DATE)); for (int i = 0; i < 6; i++) { calendar.add(Calendar.DATE, 1); String str = calendar.get(Calendar.MONTH) + 1 + "." + calendar.get(Calendar.DATE); list.add(str);//w w w. j ava 2 s . co m } return list; }
From source file:com.whatlookingfor.common.utils.DateUtils.java
/** * /*from w w w . j a va2 s. c o m*/ * * @param date * @param field ,?Calendar.YEAR,Calendar.MONTH,Calendar.DAY_OF_YEAR * @param amount * @return ? */ public static Date addDate(Date date, int field, int amount) { if (date == null) { return null; } Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(field, amount); return calendar.getTime(); }
From source file:com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImplTest.java
/** * Runs actions before test is initialized. * //from ww w . j a v a2s . c o m * @throws java.lang.Exception */ @BeforeClass public static void setUpBeforeClass() throws Exception { logger.info("Beginning tests for com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImpl"); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -3); yesterday = dateFormat.format(cal.getTime()); StringBuilder canonicalYesterday = new StringBuilder(yesterday); canonicalYesterday.replace(10, 11, "%20"); query = "search?jql=updatedDate%3E=%22" + canonicalYesterday + "%22+order+by+updated"; }
From source file:net.firejack.platform.core.utils.DateUtils.java
/** * Increments the date by one day//from w w w. j av a2 s . c o m * @param date - date to be incremented */ public static void incDateByDay(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.DAY_OF_MONTH, 1); date.setTime(cal.getTimeInMillis()); }
From source file:net.firejack.platform.core.utils.DateUtils.java
/** * Decrements the date by one hour//from ww w .j a v a 2 s . c om * @param date - date to be decremented */ public static void decDateByHour(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.HOUR, -1); date.setTime(cal.getTimeInMillis()); }