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

How to use
setTime
method
in
java.util.Calendar

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

Refine searchRefine arrow

  • Calendar.getInstance
  • Calendar.getTime
  • Calendar.get
  • Calendar.add
  • Date.<init>
  • SimpleDateFormat.<init>
  • Calendar.set
origin: spring-projects/spring-framework

  @Override
  public Calendar convert(Date source) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(source);
    return calendar;
  }
}
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

 Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.setTime(date1);
cal2.setTime(date2);
boolean sameDay = cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
         cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
origin: stackoverflow.com

 java.util.Date date= new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int month = cal.get(Calendar.MONTH);
origin: stackoverflow.com

 String myDateString = "13:24:40";
//SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
//the above commented line was changed to the one below, as per Grodriguez's pertinent comment:
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
Date date = sdf.parse(myDateString);

Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance
calendar.setTime(date);   // assigns calendar to given date 
int hour = calendar.get(Calendar.HOUR);
int minute; /... similar methods for minutes and seconds
origin: elastic/elasticsearch-hadoop

@Test
public void testCalendar() {
  Date d = new Date(0);
  Calendar cal = Calendar.getInstance();
  cal.setTime(d);
  assertThat(jdkTypeToJson(cal), containsString(new SimpleDateFormat("yyyy-MM-dd").format(d)));
}
origin: ctripcorp/apollo

private Calendar calExpiredTime() {
 Calendar calendar = Calendar.getInstance();
 calendar.setTime(DateUtils.addHours(new Date(), portalConfig.survivalDuration()));
 return calendar;
}
origin: stackoverflow.com

 Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
cal.setTime(sdf.parse("Mon Mar 14 16:02:37 GMT 2011"));// all done
origin: ch.qos.logback/logback-classic

  String computeTimeStampString(long now) {
    synchronized (this) {
      // Since the formatted output is only precise to the second, we can use the same cached string if the
      // current
      // second is the same (stripping off the milliseconds).
      if ((now / 1000) != lastTimestamp) {
        lastTimestamp = now / 1000;
        Date nowDate = new Date(now);
        calendar.setTime(nowDate);
        timesmapStr = String.format("%s %2d %s", simpleMonthFormat.format(nowDate), calendar.get(Calendar.DAY_OF_MONTH),
                simpleTimeFormat.format(nowDate));
      }
      return timesmapStr;
    }
  }
}
origin: stackoverflow.com

 SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date convertedDate = dateFormat.parse(date);
Calendar c = Calendar.getInstance();
c.setTime(convertedDate);
c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
origin: spring-projects/spring-framework

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

/**
 * Returns true if the given calendar matches
 */
boolean check(Calendar cal) {
  Calendar checkCal = cal;
  if(specTimezone != null && !specTimezone.isEmpty()) {
    Calendar tzCal = Calendar.getInstance(TimeZone.getTimeZone(specTimezone));
    tzCal.setTime(cal.getTime());
    checkCal = tzCal;
  }
  if(!checkBits(bits[0],checkCal.get(MINUTE)))
    return false;
  if(!checkBits(bits[1],checkCal.get(HOUR_OF_DAY)))
    return false;
  if(!checkBits(bits[2],checkCal.get(DAY_OF_MONTH)))
    return false;
  if(!checkBits(bits[3],checkCal.get(MONTH)+1))
    return false;
  if(!checkBits(dayOfWeek,checkCal.get(Calendar.DAY_OF_WEEK)-1))
    return false;
  return true;
}
origin: springside/springside4

private static int getWithMondayFirst(final Date date, int field) {
  Validate.notNull(date, "The date must not be null");
  Calendar cal = Calendar.getInstance();
  cal.setFirstDayOfWeek(Calendar.MONDAY);
  cal.setTime(date);
  return cal.get(field);
}
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: stackoverflow.com

 Calendar c = Calendar.getInstance(); 
c.setTime(dt); 
c.add(Calendar.DATE, 1);
dt = c.getTime();
origin: stackoverflow.com

 Date date = new Date();   // given date
Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance
calendar.setTime(date);   // assigns calendar to given date 
calendar.get(Calendar.HOUR_OF_DAY); // gets hour in 24h format
calendar.get(Calendar.HOUR);        // gets hour in 12h format
calendar.get(Calendar.MONTH);       // gets month number, NOTE this is zero based!
origin: stackoverflow.com

Date date; // your date
 Calendar cal = Calendar.getInstance();
 cal.setTime(date);
 int year = cal.get(Calendar.YEAR);
 int month = cal.get(Calendar.MONTH);
 int day = cal.get(Calendar.DAY_OF_MONTH);
 // etc.
origin: stackoverflow.com

 public static void main(String[] args) throws ParseException {

  DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
  Date lastDec2010 = sdf.parse("31/12/2010");

  Calendar calUs = Calendar.getInstance(Locale.US);       
  calUs.setTime(lastDec2010);

  Calendar calDe = Calendar.getInstance(Locale.GERMAN);       
  calDe.setTime(lastDec2010);

  System.out.println( "us: " + calUs.get( Calendar.WEEK_OF_YEAR ) ); 
  System.out.println( "de: " + calDe.get( Calendar.WEEK_OF_YEAR ) );
}
origin: ben-manes/caffeine

@Test
public void deepCopy_calendar() {
 Calendar calendar = Calendar.getInstance();
 calendar.setTime(new Date());
 assertThat(copy(calendar), is(equalTo(calendar)));
}
origin: stackoverflow.com

String strThatDay = "1985/08/25";
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
Date d = null;
try {
 d = formatter.parse(strThatDay);//catch exception
} catch (ParseException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
} 
Calendar thatDay = Calendar.getInstance();
thatDay.setTime(d); //rest is the same....
java.utilCalendarsetTime

Javadoc

Sets the time of this Calendar.

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.
  • set
    Sets the values for the fields YEAR, MONTH,DAY_OF_MONTH, HOUR, MINUTE, andSECOND . Previous values o
  • 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 Sublime Text plugins
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