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

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

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

LocalDateTime.toDate介绍

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

The Date object created has exactly the same fields as this date-time, except when the time would be invalid due to a daylight savings gap. In that case, the time will be set to the earliest valid time after the gap.

In the case of a daylight savings overlap, the earlier instant is selected.

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. 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时区数据与Joda时区数据不同的情况。

代码示例

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

@Override
public java.sql.Timestamp getPrimitiveJavaObject(Object o) {
 final TimeStampHolder h = (TimeStampHolder) o;
 org.joda.time.LocalDateTime dateTime = new org.joda.time.LocalDateTime(h.value, org.joda.time.DateTimeZone.UTC);
 // use "toDate()" to get java.util.Date object with exactly the same fields as this Joda date-time.
 // See more in Javadoc for "LocalDateTime#toDate()"
 return new java.sql.Timestamp(dateTime.toDate().getTime());
}

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

@Override
public java.sql.Timestamp getPrimitiveJavaObject(Object o) {
 if (o == null) {
  return null;
 }
 final NullableTimeStampHolder h = (NullableTimeStampHolder) o;
 org.joda.time.LocalDateTime dateTime = new org.joda.time.LocalDateTime(h.value, org.joda.time.DateTimeZone.UTC);
 // use "toDate()" to get java.util.Date object with exactly the same fields as this Joda date-time.
 // See more in Javadoc for "LocalDateTime#toDate()"
 return new java.sql.Timestamp(dateTime.toDate().getTime());
}

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

@Override
public TimestampWritable getPrimitiveWritableObject(Object o) {
 if (o == null) {
  return null;
 }
 final NullableTimeStampHolder h = (NullableTimeStampHolder) o;
 org.joda.time.LocalDateTime dateTime = new org.joda.time.LocalDateTime(h.value, org.joda.time.DateTimeZone.UTC);
 // use "toDate()" to get java.util.Date object with exactly the same fields as this Joda date-time.
 // See more in Javadoc for "LocalDateTime#toDate()"
 return new TimestampWritable(new java.sql.Timestamp(dateTime.toDate().getTime()));
}

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

@Override
public TimestampWritable getPrimitiveWritableObject(Object o) {
 final TimeStampHolder h = (TimeStampHolder) o;
 org.joda.time.LocalDateTime dateTime = new org.joda.time.LocalDateTime(h.value, org.joda.time.DateTimeZone.UTC);
 // use "toDate()" to get java.util.Date object with exactly the same fields as this Joda date-time.
 // See more in Javadoc for "LocalDateTime#toDate()"
 return new TimestampWritable(new java.sql.Timestamp(dateTime.toDate().getTime()));
}

代码示例来源:origin: ninjaframework/ninja

@Override
public Date parseParameter(String field, String parameterValue, Validation validation) {
  if (parameterValue == null || parameterValue.isEmpty() || validation.hasViolation(field)) {
    return null;
  } else {
    try {
      return new LocalDateTime(parameterValue).toDate();
    } catch (IllegalArgumentException e) {
      validation.addViolation(new ConstraintViolation(
          IsDate.KEY, field, IsDate.MESSAGE, parameterValue));
      return null;
    }
  }
}

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

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

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

@Override
public Date convert(LocalDateTime source) {
  Assert.notNull(source, "Source must not be null!");
  return source.toDate();
}

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

public void setEnd(LocalDateTime end) {
 this.end = end;
 if (start != null && end != null) {
  this.duration = end.toDate().getTime() - start.toDate().getTime();
 }
 if (updates != null) {
  getUpdates().isEndChanged = true;
 }
}

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

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

代码示例来源:origin: yjjdick/sdb-mall

/**
 * 字符串转换成日期
 * @param strDate 日期字符串
 * @param pattern 日期的格式,如:DateUtils.DATE_TIME_PATTERN
 */
public static Date stringToDate(String strDate, String pattern) {
  if (StringUtils.isBlank(strDate)){
    return null;
  }
  DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
  return fmt.parseLocalDateTime(strDate).toDate();
}

代码示例来源:origin: com.github.blasd.apex/apex-java

@ManagedAttribute
public Date getLatestThreadDump() {
  LocalDateTime latest = latestThreadDump.get();
  if (latest == null) {
    return null;
  } else {
    return latest.toDate();
  }
}

代码示例来源:origin: stackoverflow.com

LocalDate startDate = new LocalDate(2014,1,2);

LocalDateTime startDateTime = new LocalDateTime(2014,1,2,00,0);

System.out.println(startDate.toDate());
System.out.println(startDateTime.toDate());

if(startDate.toDate().compareTo((startDateTime.toDate()))==0){
 System.out.println("equal");       
}

代码示例来源:origin: stackoverflow.com

DateTimeZone tz = DateTimeZone.getDefault();
DateTime nowLocal = new DateTime();
LocalDateTime nowUTC = nowLocal.withZone(DateTimeZone.UTC).toLocalDateTime();
DateTime nowUTC2 = nowLocal.withZone(DateTimeZone.UTC);

Date dLocal = nowLocal.toDate();
Date dUTC = nowUTC.toDate();
Date dUTC2 = nowUTC2.toDate();

代码示例来源:origin: org.apache.drill.exec/drill-java-exec

@Override
public Timestamp getTimestamp(int index) {
 org.joda.time.LocalDateTime dateTime = new org.joda.time.LocalDateTime(ac.get(index), org.joda.time.DateTimeZone.UTC);
 // use "toDate()" to get java.util.Date object with exactly the same fields as this Joda date-time.
 // See more in Javadoc for "LocalDateTime#toDate()"
 return new Timestamp(dateTime.toDate().getTime());
}

代码示例来源:origin: org.apache.drill.exec/drill-java-exec

@Override
public Timestamp getTimestamp(int index) {
 if (ac.isNull(index)) {
  return null;
 }
 org.joda.time.LocalDateTime dateTime = new org.joda.time.LocalDateTime(ac.get(index), org.joda.time.DateTimeZone.UTC);
 // use "toDate()" to get java.util.Date object with exactly the same fields as this Joda date-time.
 // See more in Javadoc for "LocalDateTime#toDate()"
 return new Timestamp(dateTime.toDate().getTime());
}

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

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

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

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

代码示例来源:origin: com.atlassian.jira/jira-core

@Override
public Date parse(String text, DateTimeZone timeZone, Locale locale)
{
  DateTimeFormatter formatter = cache.get(new JodaFormatterSupplier.Key(pattern(), locale)).withZone(timeZone);
  // We convert to a local time first to avoid weirdness around Daylight Savings cut over times, esp
  // in Time Zones where the DST cut over is at midnight.  See https://jira.atlassian.com/browse/JRA-22582
  LocalDateTime localDateTime = formatter.parseLocalDateTime(text);
  return localDateTime.toDate(timeZone.toTimeZone());
}

代码示例来源:origin: com.vlkan.rfos/rotating-fos

@Override
public void start(Rotatable rotatable) {
  RotationConfig config = rotatable.getConfig();
  LocalDateTime triggerDateTime = getTriggerDateTime(config.getClock());
  TimerTask timerTask = createTimerTask(rotatable, triggerDateTime);
  config.getTimer().schedule(timerTask, triggerDateTime.toDate());
}

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

public DBObject createLockUpdate() {
 return BasicDBObjectBuilder.start()
  .push("$set")
   .push(LOCK)
    .add(Lock.TIME, Time.now().toDate())
    .add(Lock.OWNER, workflowEngine.getId())
   .pop()
  .pop()
  .get();
}

相关文章