java.util.Calendar.getTime()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中java.util.Calendar.getTime()方法的一些代码示例,展示了Calendar.getTime()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Calendar.getTime()方法的具体详情如下:
包路径:java.util.Calendar
类名称:Calendar
方法名:getTime

Calendar.getTime介绍

[英]Returns the time of this Calendar as a Date object.
[中]将此日历的时间作为日期对象返回。

代码示例

代码示例来源: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: 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

Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 1988);
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DAY_OF_MONTH, 1);
Date dateRepresentation = cal.getTime();

代码示例来源:origin: stanfordnlp/CoreNLP

/** helper for return current date **/
public String currentDate() {
 return new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
}

代码示例来源: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: alibaba/fastjson

public void write(JSONSerializer serializer, Object object, BeanContext context) throws IOException {
  SerializeWriter out = serializer.out;
  String format = context.getFormat();
  Calendar calendar = (Calendar) object;
  if (format.equals("unixtime")) {
    long seconds = calendar.getTimeInMillis() / 1000L;
    out.writeInt((int) seconds);
    return;
  }
  DateFormat dateFormat = new SimpleDateFormat(format);
  if (dateFormat == null) {
    dateFormat = new SimpleDateFormat(JSON.DEFFAULT_DATE_FORMAT, serializer.locale);
    dateFormat.setTimeZone(serializer.timeZone);
  }
  String text = dateFormat.format(calendar.getTime());
  out.writeString(text);
}

代码示例来源:origin: org.testng/testng

@Override
public boolean isSkip() {
 if (null == m_expireDate) {
  return false;
 }
 try {
  Calendar now= Calendar.getInstance();
  Date nowDate= m_inFormat.parse(m_inFormat.format(now.getTime()));
  now.setTime(nowDate);
  return !now.after(m_expireDate);
 }
 catch(ParseException pex) {
  throw new TestNGException("Cannot compare dates.");
 }
}

代码示例来源: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: spring-projects/spring-framework

private Date getDate(int year, int month, int dayOfMonth, int hour, int minute, int second, int millisecond) {
  Calendar cal = Calendar.getInstance(Locale.US);
  cal.setTimeZone(UTC);
  cal.clear();
  cal.set(Calendar.YEAR, year);
  cal.set(Calendar.MONTH, month);
  cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
  cal.set(Calendar.HOUR, hour);
  cal.set(Calendar.MINUTE, minute);
  cal.set(Calendar.SECOND, second);
  cal.set(Calendar.MILLISECOND, millisecond);
  return cal.getTime();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testIncrementSecondWithPreviousExecutionTooEarly() throws Exception {
  CronTrigger trigger = new CronTrigger("11 * * * * *", timeZone);
  calendar.set(Calendar.SECOND, 11);
  SimpleTriggerContext context = new SimpleTriggerContext();
  context.update(calendar.getTime(), new Date(calendar.getTimeInMillis() - 100),
      new Date(calendar.getTimeInMillis() - 90));
  calendar.add(Calendar.MINUTE, 1);
  assertEquals(calendar.getTime(), trigger.nextExecutionTime(context));
}

代码示例来源: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: spring-projects/spring-framework

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

// Create an instance of SimpleDateFormat used for formatting 
// the string representation of date (month/day/year)
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

// Get the date today using Calendar object.
Date today = Calendar.getInstance().getTime();        
// Using DateFormat format method we can create a string 
// representation of a date with the defined format.
String reportDate = df.format(today);

// Print what date is today!
System.out.println("Report Date: " + reportDate);

代码示例来源: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: org.testng/testng

static String timeAsGmt() {
 SimpleDateFormat sdf = new SimpleDateFormat();
 sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
 sdf.applyPattern("dd MMM yyyy HH:mm:ss z");
 return sdf.format(Calendar.getInstance().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: stackoverflow.com

Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
System.out.println("Yesterday's date = "+ cal.getTime());

代码示例来源: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: stackoverflow.com

Calendar c = Calendar.getInstance(); 
c.setTime(dt); 
c.add(Calendar.DATE, 1);
dt = c.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();
}

相关文章