本文整理了Java中java.util.Calendar.setTime()
方法的一些代码示例,展示了Calendar.setTime()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Calendar.setTime()
方法的具体详情如下:
包路径:java.util.Calendar
类名称:Calendar
方法名:setTime
[英]Sets the time of this Calendar.
[中]设置此日历的时间。
代码示例来源: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....
内容来源于网络,如有侵权,请联系作者删除!