congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Calendar.add
Code IndexAdd Tabnine to your IDE (free)

How to use
add
method
in
java.util.Calendar

Best Java code snippets using java.util.Calendar.add (Showing top 20 results out of 16,344)

Refine searchRefine arrow

  • Calendar.getInstance
  • Calendar.getTime
  • Calendar.setTime
  • Calendar.set
  • SimpleDateFormat.<init>
  • Calendar.get
  • Calendar.getTimeInMillis
origin: ctripcorp/apollo

/**
 * Currently the instance config is expired by 1 day, add one more hour to avoid possible time
 * difference
 */
private Date getValidInstanceConfigDate() {
 Calendar cal = Calendar.getInstance();
 cal.add(Calendar.DATE, -1);
 cal.add(Calendar.HOUR, -1);
 return cal.getTime();
}
origin: stackoverflow.com

 String dt = "2008-01-01";  // Start date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(sdf.parse(dt));
c.add(Calendar.DATE, 1);  // number of days to add
dt = sdf.format(c.getTime());  // dt is now the new date
origin: stackoverflow.com

 // today    
Calendar date = new GregorianCalendar();
// reset hour, minutes, seconds and millis
date.set(Calendar.HOUR_OF_DAY, 0);
date.set(Calendar.MINUTE, 0);
date.set(Calendar.SECOND, 0);
date.set(Calendar.MILLISECOND, 0);

// next day
date.add(Calendar.DAY_OF_MONTH, 1);
origin: spring-projects/spring-framework

@Test
public void testIncrementDayOfMonthByOne() throws Exception {
  CronTrigger trigger = new CronTrigger("* * * 10 * *", timeZone);
  calendar.set(Calendar.DAY_OF_MONTH, 9);
  Date date = calendar.getTime();
  calendar.add(Calendar.DAY_OF_MONTH, 1);
  calendar.set(Calendar.HOUR_OF_DAY, 0);
  calendar.set(Calendar.MINUTE, 0);
  calendar.set(Calendar.SECOND, 0);
  TriggerContext context = getTriggerContext(date);
  assertEquals(calendar.getTime(), trigger.nextExecutionTime(context));
}
origin: north2016/T-MVP

public static List<String> getOldWeekDays() {
  final Calendar c = Calendar.getInstance();
  String[] months = new String[8];
  for (int i = 0; i < 8; i++) {
    months[i] = new SimpleDateFormat("MM.dd").format(new Date(c
        .getTimeInMillis()));
    c.add(Calendar.DAY_OF_MONTH, -1);
  }
  return Arrays.asList(months);
}
origin: spring-projects/spring-framework

calendar.setTime(date);
calendar.set(Calendar.MILLISECOND, 0);
long originalTimestamp = calendar.getTimeInMillis();
doNext(calendar, calendar.get(Calendar.YEAR));
if (calendar.getTimeInMillis() == originalTimestamp) {
  calendar.add(Calendar.SECOND, 1);
  doNext(calendar, calendar.get(Calendar.YEAR));
return calendar.getTime();
origin: jaydenxiao2016/AndroidFire

public static String getCurrentDay2() {
  String curDateTime = null;
  try {
    SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(dateFormatYMDHMS);
    Calendar c = new GregorianCalendar();
    c.add(Calendar.DAY_OF_MONTH, 0);
    curDateTime = mSimpleDateFormat.format(c.getTime());
  } catch (Exception e) {
    e.printStackTrace();
  }
  return curDateTime;
}
origin: stackoverflow.com

 Date whateverDateYouWant = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(whateverDateYouWant);

int unroundedMinutes = calendar.get(Calendar.MINUTE);
int mod = unroundedMinutes % 15;
calendar.add(Calendar.MINUTE, mod < 8 ? -mod : (15-mod));
origin: kiegroup/jbpm

private Timestamp getTomorrow() {
  Calendar c = Calendar.getInstance();
  c.setTime(getToday());
  c.add(Calendar.DATE, 1);
  return new Timestamp(c.getTimeInMillis());
}
origin: robovm/robovm

private SimpleDateFormat(Locale locale) {
  numberFormat = NumberFormat.getInstance(locale);
  numberFormat.setParseIntegerOnly(true);
  numberFormat.setGroupingUsed(false);
  calendar = new GregorianCalendar(locale);
  calendar.add(Calendar.YEAR, -80);
  creationYear = calendar.get(Calendar.YEAR);
  defaultCenturyStart = calendar.getTime();
}
origin: Activiti/Activiti

protected Date calculateDueDate(CommandContext commandContext, int waitTimeInSeconds, Date oldDate) {
 Calendar newDateCal = new GregorianCalendar();
 if (oldDate != null) {
  newDateCal.setTime(oldDate);
 } else {
  newDateCal.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
 }
 newDateCal.add(Calendar.SECOND, waitTimeInSeconds);
 return newDateCal.getTime();
}
origin: apache/drill

protected Calendar nextDay(Date date, int dayOfWeek) {
 calendar.setTime(date);
 int currDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
 int daysToAdd;
 if (currDayOfWeek < dayOfWeek) {
  daysToAdd = dayOfWeek - currDayOfWeek;
 } else {
  daysToAdd = 7 - currDayOfWeek + dayOfWeek;
 }
 calendar.add(Calendar.DATE, daysToAdd);
 return calendar;
}
origin: rey5137/material

private static long gotoFirstDayOfWeek(Calendar cal){
  int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
  int firstDayOfWeek = cal.getFirstDayOfWeek();
  int shift = dayOfWeek >= firstDayOfWeek ? (dayOfWeek - firstDayOfWeek) : (dayOfWeek + 7 - firstDayOfWeek);
  cal.add(Calendar.DAY_OF_MONTH, -shift);
  return cal.getTimeInMillis();
}
origin: apache/activemq

protected static long doUpdateCurrentMonth(Calendar working, CronEntry month) throws MessageFormatException {
  int currentMonth = working.get(Calendar.MONTH) + 1;
  if (!isCurrent(month, currentMonth)) {
    int nextMonth = getNext(month, currentMonth, working);
    working.add(Calendar.MONTH, nextMonth);
    // Reset to start of month.
    resetToStartOfDay(working, 1);
    return working.getTimeInMillis();
  }
  return 0L;
}
origin: spring-projects/spring-framework

private int findNextDay(Calendar calendar, BitSet daysOfMonth, int dayOfMonth, BitSet daysOfWeek, int dayOfWeek,
    List<Integer> resets) {
  int count = 0;
  int max = 366;
  // the DAY_OF_WEEK values in java.util.Calendar start with 1 (Sunday),
  // but in the cron pattern, they start with 0, so we subtract 1 here
  while ((!daysOfMonth.get(dayOfMonth) || !daysOfWeek.get(dayOfWeek - 1)) && count++ < max) {
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
    dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
    reset(calendar, resets);
  }
  if (count >= max) {
    throw new IllegalArgumentException("Overflow in day for expression \"" + this.expression + "\"");
  }
  return dayOfMonth;
}
origin: stackoverflow.com

 Calendar c = Calendar.getInstance(); 
c.setTime(dt); 
c.add(Calendar.DATE, 1);
dt = c.getTime();
origin: spring-projects/spring-framework

@Test
public void testIncrementDayOfMonthAndRollover() throws Exception {
  CronTrigger trigger = new CronTrigger("* * * 10 * *", timeZone);
  calendar.set(Calendar.DAY_OF_MONTH, 11);
  Date date = calendar.getTime();
  calendar.add(Calendar.MONTH, 1);
  calendar.set(Calendar.DAY_OF_MONTH, 10);
  calendar.set(Calendar.HOUR_OF_DAY, 0);
  calendar.set(Calendar.MINUTE, 0);
  calendar.set(Calendar.SECOND, 0);
  TriggerContext context = getTriggerContext(date);
  assertEquals(calendar.getTime(), trigger.nextExecutionTime(context));
}
origin: AsyncHttpClient/async-http-client

/**
 * Sets the Date and Cache headers for the HTTP Response
 *
 * @param response    HTTP response
 * @param fileToCache file to extract content type
 */
private static void setDateAndCacheHeaders(HttpResponse response, File fileToCache) {
 SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
 dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE));
 // Date header
 Calendar time = new GregorianCalendar();
 response.headers().set(DATE, dateFormatter.format(time.getTime()));
 // Add cache headers
 time.add(Calendar.SECOND, HTTP_CACHE_SECONDS);
 response.headers().set(EXPIRES, dateFormatter.format(time.getTime()));
 response.headers().set(CACHE_CONTROL, "private, max-age=" + HTTP_CACHE_SECONDS);
 response.headers().set(
     LAST_MODIFIED, dateFormatter.format(new Date(fileToCache.lastModified())));
}
origin: stackoverflow.com

 Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
System.out.println("Yesterday's date = "+ cal.getTime());
origin: org.springframework/spring-context

private int findNextDay(Calendar calendar, BitSet daysOfMonth, int dayOfMonth, BitSet daysOfWeek, int dayOfWeek,
    List<Integer> resets) {
  int count = 0;
  int max = 366;
  // the DAY_OF_WEEK values in java.util.Calendar start with 1 (Sunday),
  // but in the cron pattern, they start with 0, so we subtract 1 here
  while ((!daysOfMonth.get(dayOfMonth) || !daysOfWeek.get(dayOfWeek - 1)) && count++ < max) {
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
    dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
    reset(calendar, resets);
  }
  if (count >= max) {
    throw new IllegalArgumentException("Overflow in day for expression \"" + this.expression + "\"");
  }
  return dayOfMonth;
}
java.utilCalendaradd

Javadoc

Adds the given amount to a Calendar field.

Popular methods of Calendar

  • getInstance
    Gets a calendar with the specified time zone and locale. The Calendar returned is based on the curre
  • getTime
    Returns a Date object representing thisCalendar's time value (millisecond offset from the Epoch").
  • get
    Returns the value of the given calendar field. In lenient mode, all calendar fields are normalized.
  • setTime
    Sets this Calendar's time with the given Date. Note: Calling setTime() withDate(Long.MAX_VALUE) or D
  • set
    Sets the values for the fields YEAR, MONTH,DAY_OF_MONTH, HOUR, MINUTE, andSECOND . Previous values o
  • getTimeInMillis
    Returns this Calendar's time value in milliseconds.
  • setTimeInMillis
    Sets this Calendar's current time from the given long value.
  • getTimeZone
    Gets the time zone.
  • clear
    Sets the given calendar field value and the time value (millisecond offset from the Epoch) of this C
  • setTimeZone
    Sets the time zone with the given time zone value.
  • clone
    Creates and returns a copy of this object.
  • before
    Returns whether this Calendar represents a time before the time represented by the specifiedObject.
  • clone,
  • before,
  • getActualMaximum,
  • after,
  • setLenient,
  • getFirstDayOfWeek,
  • equals,
  • compareTo,
  • setFirstDayOfWeek

Popular in Java

  • Making http post requests using okhttp
  • getApplicationContext (Context)
  • getSharedPreferences (Context)
  • getExternalFilesDir (Context)
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • JFileChooser (javax.swing)
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now