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

How to use
set
method
in
java.util.Calendar

Best Java code snippets using java.util.Calendar.set (Showing top 20 results out of 21,852)

Refine searchRefine arrow

  • Calendar.getInstance
  • Calendar.getTime
  • Calendar.getTimeInMillis
  • Calendar.get
  • Calendar.setTime
  • Calendar.add
origin: ctripcorp/apollo

private static Date getDayBeginTime(Date date) {
 Calendar calendar = Calendar.getInstance();
 calendar.setTime(date);
 calendar.set(Calendar.HOUR, 0);
 calendar.set(Calendar.MINUTE, 0);
 calendar.set(Calendar.SECOND, 0);
 calendar.set(Calendar.MILLISECOND, 0);
 return new Date(calendar.getTime().getTime());
}
origin: stackoverflow.com

 Calendar cal = Calendar.getInstance(); // locale-specific
cal.setTime(dateObject);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
long time = cal.getTimeInMillis();
origin: apache/incubator-dubbo

/**
 * between 2:00 am to 6:00 am, the time is random.
 *
 * @return
 */
long calculateStartTime() {
  Calendar calendar = Calendar.getInstance();
  long nowMill = calendar.getTimeInMillis();
  calendar.set(Calendar.HOUR_OF_DAY, 0);
  calendar.set(Calendar.MINUTE, 0);
  calendar.set(Calendar.SECOND, 0);
  calendar.set(Calendar.MILLISECOND, 0);
  long subtract = calendar.getTimeInMillis() + ONE_DAY_IN_MIll - nowMill;
  return subtract + (FOUR_HOURS_IN_MIll / 2) + ThreadLocalRandom.current().nextInt(FOUR_HOURS_IN_MIll);
}
origin: spring-projects/spring-framework

private Date getDate() {
  Calendar cal = Calendar.getInstance();
  cal.set(Calendar.YEAR, 10);
  cal.set(Calendar.MONTH, 10);
  cal.set(Calendar.DATE, 10);
  cal.set(Calendar.HOUR, 10);
  cal.set(Calendar.MINUTE, 10);
  cal.set(Calendar.SECOND, 10);
  return cal.getTime();
}
origin: apache/kylin

public static long getYearStart(long ts) {
  Calendar calendar = Calendar.getInstance(gmt, Locale.ROOT);
  calendar.setTimeInMillis(ts);
  int year = calendar.get(Calendar.YEAR);
  calendar.clear();
  calendar.set(year, 0, 1);
  return calendar.getTimeInMillis();
}
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: apache/rocketmq

private synchronized static void setStartTime(long millis) {
  Calendar cal = Calendar.getInstance();
  cal.setTimeInMillis(millis);
  cal.set(Calendar.DAY_OF_MONTH, 1);
  cal.set(Calendar.HOUR_OF_DAY, 0);
  cal.set(Calendar.MINUTE, 0);
  cal.set(Calendar.SECOND, 0);
  cal.set(Calendar.MILLISECOND, 0);
  startTime = cal.getTimeInMillis();
  cal.add(Calendar.MONTH, 1);
  nextStartTime = cal.getTimeInMillis();
}
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: stanfordnlp/CoreNLP

 private static Calendar copyCalendar(Calendar c) {
  Calendar date = Calendar.getInstance();
  date.clear();
  date.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.HOUR_OF_DAY), c
    .get(Calendar.MINUTE), c.get(Calendar.SECOND));
  return date;
 }
}
origin: stackoverflow.com

 public static Calendar getDatePart(Date date){
  Calendar cal = Calendar.getInstance();       // get calendar instance
  cal.setTime(date);      
  cal.set(Calendar.HOUR_OF_DAY, 0);            // set hour to midnight
  cal.set(Calendar.MINUTE, 0);                 // set minute in hour
  cal.set(Calendar.SECOND, 0);                 // set second in minute
  cal.set(Calendar.MILLISECOND, 0);            // set millisecond in second

  return cal;                                  // return the date part
}
origin: quartz-scheduler/quartz

private boolean daylightSavingHourShiftOccurredAndAdvanceNeeded(Calendar newTime, int initialHourOfDay, Date afterTime) {
  if(isPreserveHourOfDayAcrossDaylightSavings() && newTime.get(Calendar.HOUR_OF_DAY) != initialHourOfDay) {
    newTime.set(Calendar.HOUR_OF_DAY, initialHourOfDay);
    if (newTime.get(Calendar.HOUR_OF_DAY) != initialHourOfDay) {
      return isSkipDayIfHourDoesNotExist();
    } else {
      return !newTime.getTime().after(afterTime);
    }
  }
  return false;
}

origin: spring-projects/spring-framework

@Test
public void testMonthlyTriggerInShortMonth() throws Exception {
  CronTrigger trigger = new CronTrigger("0 0 0 1 * *", timeZone);
  calendar.set(Calendar.MONTH, 9);
  calendar.set(Calendar.DAY_OF_MONTH, 30);
  Date date = calendar.getTime();
  calendar.set(Calendar.MONTH, 10);
  calendar.set(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: redisson/redisson

/**
 * Advance the calendar to the particular hour paying particular attention
 * to daylight saving problems.
 * 
 * @param cal the calendar to operate on
 * @param hour the hour to set
 */
protected void setCalendarHour(Calendar cal, int hour) {
  cal.set(java.util.Calendar.HOUR_OF_DAY, hour);
  if (cal.get(java.util.Calendar.HOUR_OF_DAY) != hour && hour != 24) {
    cal.set(java.util.Calendar.HOUR_OF_DAY, hour + 1);
  }
}
origin: jenkinsci/jenkins

  @Override
  void setTo(Calendar c, int i) {
    int v = i-offset;
    int was = c.get(field);
    c.set(field,v);
    final int firstDayOfWeek = c.getFirstDayOfWeek();
    if (v < firstDayOfWeek && was >= firstDayOfWeek) {
      // in crontab, the first DoW is always Sunday, but in Java, it can be Monday or in theory arbitrary other days.
      // When first DoW is 1/2 Monday, calendar points to 1/2 Monday, setting the DoW to Sunday makes
      // the calendar moves forward to 1/8 Sunday, instead of 1/1 Sunday. So we need to compensate that effect here.
      addTo(c,-7);
    } else if (was < firstDayOfWeek && firstDayOfWeek <= v) {
      // If we wrap the other way around, we need to adjust in the opposite direction of above.
      addTo(c, 7);
    }
  }
};
origin: spring-projects/spring-framework

private void roundup(Calendar calendar) {
  calendar.add(Calendar.SECOND, 1);
  calendar.set(Calendar.MILLISECOND, 0);
}
origin: macrozheng/mall

  /**
   * 从Date类型的时间中提取时间部分
   */
  public static Date getTime(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.YEAR, 1970);
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    return calendar.getTime();
  }
}
origin: spring-projects/spring-framework

private Date getDate() {
  Calendar cal = Calendar.getInstance();
  cal.set(Calendar.YEAR, 10);
  cal.set(Calendar.MONTH, 10);
  cal.set(Calendar.DATE, 10);
  cal.set(Calendar.HOUR, 10);
  cal.set(Calendar.MINUTE, 10);
  cal.set(Calendar.SECOND, 10);
  return cal.getTime();
}
origin: apache/kylin

public static long getQuarterStart(long ts) {
  Calendar calendar = Calendar.getInstance(gmt, Locale.ROOT);
  calendar.setTimeInMillis(ts);
  int year = calendar.get(Calendar.YEAR);
  int month = calendar.get(Calendar.MONTH);
  calendar.clear();
  calendar.set(year, month / 3 * 3, 1);
  return calendar.getTimeInMillis();
}
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: apache/rocketmq

public static long computNextMorningTimeMillis() {
  Calendar cal = Calendar.getInstance();
  cal.setTimeInMillis(System.currentTimeMillis());
  cal.add(Calendar.DAY_OF_MONTH, 1);
  cal.set(Calendar.HOUR_OF_DAY, 0);
  cal.set(Calendar.MINUTE, 0);
  cal.set(Calendar.SECOND, 0);
  cal.set(Calendar.MILLISECOND, 0);
  return cal.getTimeInMillis();
}
java.utilCalendarset

Javadoc

Sets the given field to the given value.

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
  • add
    Adds or subtracts the specified amount of time to the given calendar field, based on the calendar's
  • 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)
  • Top 12 Jupyter Notebook extensions
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