org.joda.time.LocalDate.toDate()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(175)

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

LocalDate.toDate介绍

[英]Get the date time as a java.util.Date.

The Date object created has exactly the same year, month and day as this date. The time will be set to the earliest valid time for that date.

Converting to a JDK Date is full of complications as the JDK Date constructor doesn't behave as you might expect around DST transitions. This method works by taking a first guess and then adjusting the JDK date until it has the earliest valid instant. This also handles the situation where the JDK time zone data differs from the Joda-Time time zone data.
[中]获取日期时间作为java.util.Date
创建的Date对象的年、月和日与此日期完全相同。时间将设置为该日期的最早有效时间。
转换为JDK日期充满了复杂性,因为JDK日期构造函数在DST转换前后的行为可能与您预期的不同。这种方法的工作原理是先猜测,然后调整JDK日期,直到它拥有最早的有效瞬间。这还可以处理JDK时区数据与Joda时区数据不同的情况。

代码示例

代码示例来源:origin: apache/flink

private Date convertToDate(Object object) {
  final long millis;
  if (object instanceof Integer) {
    final Integer value = (Integer) object;
    // adopted from Apache Calcite
    final long t = (long) value * 86400000L;
    millis = t - (long) LOCAL_TZ.getOffset(t);
  } else {
    // use 'provided' Joda time
    final LocalDate value = (LocalDate) object;
    millis = value.toDate().getTime();
  }
  return new Date(millis);
}

代码示例来源:origin: apache/drill

@Override
public java.sql.Date getPrimitiveJavaObject(Object o) {
 final DateHolder h = (DateHolder) o;
 org.joda.time.LocalDate localDate = new org.joda.time.LocalDate(h.value, org.joda.time.DateTimeZone.UTC);
 // Use "toDate()" to get java.util.Date object with exactly the same year the same year, month and day as Joda date.
 // See more in Javadoc for "LocalDate#toDate()"
 return new java.sql.Date(localDate.toDate().getTime());
}

代码示例来源:origin: apache/drill

@Override
public java.sql.Date getPrimitiveJavaObject(Object o) {
 if (o == null) {
  return null;
 }
 final NullableDateHolder h = (NullableDateHolder) o;
 org.joda.time.LocalDate localDate = new org.joda.time.LocalDate(h.value, org.joda.time.DateTimeZone.UTC);
 // Use "toDate()" to get java.util.Date object with exactly the same year the same year, month and day as Joda date.
 // See more in Javadoc for "LocalDate#toDate()"
 return new java.sql.Date(localDate.toDate().getTime());
}

代码示例来源:origin: killbill/killbill

@Override
  public List<RolledUpUsageModelDao> getRawUsageForAccount(final LocalDate startDate, final LocalDate endDate, final InternalTenantContext context) {
    return dbRouter.onDemand(true).getRawUsageForAccount(startDate.toDate(), endDate.toDate(), context);
  }
}

代码示例来源:origin: killbill/killbill

@Override
public List<RolledUpUsageModelDao> getAllUsageForSubscription(final UUID subscriptionId, final LocalDate startDate, final LocalDate endDate, final InternalTenantContext context) {
  return dbRouter.onDemand(true).getAllUsageForSubscription(subscriptionId, startDate.toDate(), endDate.toDate(), context);
}

代码示例来源:origin: apache/drill

@Override
public DateWritable getPrimitiveWritableObject(Object o) {
 if (o == null) {
  return null;
 }
 final NullableDateHolder h = (NullableDateHolder) o;
 org.joda.time.LocalDate localDate = new org.joda.time.LocalDate(h.value, org.joda.time.DateTimeZone.UTC);
 // Use "toDate()" to get java.util.Date object with exactly the same year the same year, month and day as Joda date.
 // See more in Javadoc for "LocalDate#toDate()"
 return new DateWritable(new java.sql.Date(localDate.toDate().getTime()));
}

代码示例来源:origin: apache/drill

@Override
public DateWritable getPrimitiveWritableObject(Object o) {
 final DateHolder h = (DateHolder) o;
 org.joda.time.LocalDate localDate = new org.joda.time.LocalDate(h.value, org.joda.time.DateTimeZone.UTC);
 // Use "toDate()" to get java.util.Date object with exactly the same year the same year, month and day as Joda date.
 // See more in Javadoc for "LocalDate#toDate()"
 return new DateWritable(new java.sql.Date(localDate.toDate().getTime()));
}

代码示例来源:origin: killbill/killbill

@Override
public List<RolledUpUsageModelDao> getUsageForSubscription(final UUID subscriptionId, final LocalDate startDate, final LocalDate endDate, final String unitType, final InternalTenantContext context) {
  return dbRouter.onDemand(true).getUsageForSubscription(subscriptionId, startDate.toDate(), endDate.toDate(), unitType, context);
}

代码示例来源:origin: benas/random-beans

/**
 * Create a new {@link JodaTimeLocalDateRangeRandomizer}.
 * @param min date
 * @param max date
 * @param seed initial seed
 */
public JodaTimeLocalDateRangeRandomizer(final LocalDate min, final LocalDate max, final long seed) {
  super(min.toDate(), max.toDate(), seed);
}

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

assertEquals(LocalDate.parse("2009-10-31").toDate(), handler.date);
assertEquals(Double.valueOf(0.9999), handler.percent);

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Override
  public Date convert(LocalDate in, Context context) throws Exception {
    if (in == null) return null;
    return in.toDate();
  }
}

代码示例来源:origin: br.com.objectos/way-io

@Override
void write(Cell cell) {
 cell.setCellType(Cell.CELL_TYPE_NUMERIC);
 LocalDate cellValue = date;
 if (cellValue != null) {
  Date value = cellValue.toDate();
  cell.setCellValue(value);
 }
}

代码示例来源:origin: com.github.fosin/cdp-utils

/**
 * get$dateOfNextYear
 *
 * @return a {@link java.util.Date} object.
 */
public Date get$dateOfNextYear(){
  LocalDate dt = new LocalDate();
  return dt.plusYears(1).toDate();
}

代码示例来源:origin: net.rapture/Reflex

public ReflexDateValue add(Object increase) {
  if (increase instanceof Integer) {
    int amountToIncrease = ((Integer) increase).intValue();
    return new ReflexDateValue(calHandler.addDays(date.toDate(), amountToIncrease), calendarString);
  } else {
    throw new ReflexException(-1, "Cannot increase a date by something of type " + increase.getClass().toString());
  }
}

代码示例来源:origin: joda-time/joda-time-hibernate

public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException {
  if (value == null) {
    StandardBasicTypes.DATE.nullSafeSet(preparedStatement, null, index);
  } else {
    StandardBasicTypes.DATE.nullSafeSet(preparedStatement, ((LocalDate) value).toDate(), index);
  }
}

代码示例来源:origin: br.com.objectos/way-io

@Override
void apachePOI(POICell cell, Object value) {
 if (value != null) {
  LocalDate val = (LocalDate) value;
  cell.setCellType(Cell.CELL_TYPE_NUMERIC);
  cell.setCellValue(val.toDate());
 }
}

代码示例来源:origin: com.synaptix/SynaptixWidget

@Override
  public void setWritableCell(TableModel tableModel, XSSFCell cell, Object value, int row, int col) {
    LocalDate localDate = (LocalDate) value;
    cell.setCellStyle(cellStyle);
    if (localDate != null) {
      cell.setCellValue(localDate.toDate());
    }
  }
}

代码示例来源:origin: org.flowable/flowable-dmn-engine

public static Date addDate(Object startDate, Object years, Object months, Object days) {
  LocalDate currentDate = new LocalDate(startDate);
  
  currentDate = currentDate.plusYears(intValue(years));
  currentDate = currentDate.plusMonths(intValue(months));
  currentDate = currentDate.plusDays(intValue(days));
  return currentDate.toDate();
}

代码示例来源:origin: org.motechproject/motech-scheduler

@Override
public void scheduleDayOfWeekJob(DayOfWeekSchedulableJob dayOfWeekSchedulableJob) {
  logObjectIfNotNull(dayOfWeekSchedulableJob);
  MotechEvent motechEvent = dayOfWeekSchedulableJob.getMotechEvent();
  LocalDate start = dayOfWeekSchedulableJob.getStartDate();
  LocalDate end = dayOfWeekSchedulableJob.getEndDate();
  Time time = dayOfWeekSchedulableJob.getTime();
  CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.atHourAndMinuteOnGivenDaysOfWeek(time.getHour(), time.getMinute(), dayOfWeekSchedulableJob.getCronDays().toArray(new Integer[0]));
  CronTriggerImpl cronTrigger = (CronTriggerImpl) cronScheduleBuilder.build();
  CronSchedulableJob cronSchedulableJob = new CronSchedulableJob(motechEvent, cronTrigger.getCronExpression(), start.toDate(), end.toDate(), dayOfWeekSchedulableJob.isIgnorePastFiresAtStart());
  scheduleJob(cronSchedulableJob);
}

代码示例来源:origin: qcadoo/mes

private void setUpProgressForDayRow(final FormComponent progressForDayRowForm, final OrderRealizationDay realizationDay) {
  FieldComponent dayField = progressForDayRowForm.findFieldComponentByName(DAY_NUMBER_INPUT_REF);
  FieldComponent dateField = progressForDayRowForm.findFieldComponentByName(DATE_INPUT_REF);
  dayField.setFieldValue(realizationDay.getRealizationDayNumber());
  dateField.setFieldValue(DateUtils.toDateString(realizationDay.getDate().toDate()));
  AwesomeDynamicListComponent dailyProgressADL = (AwesomeDynamicListComponent) progressForDayRowForm
      .findFieldComponentByName(DAILY_PROGRESS_ADL_REF);
  dailyProgressADL.setFieldValue(fillDailyProgressWithShifts(realizationDay.getWorkingShifts()));
}

相关文章