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

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

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

Calendar.toInstant介绍

暂无

代码示例

代码示例来源:origin: oblac/jodd

public static LocalDateTime fromCalendar(final Calendar calendar) {
  TimeZone tz = calendar.getTimeZone();
  ZoneId zid = tz == null ? ZoneId.systemDefault() : tz.toZoneId();
  return LocalDateTime.ofInstant(calendar.toInstant(), zid);
}

代码示例来源:origin: hibernate/hibernate-orm

return ZonedDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() );

代码示例来源:origin: alibaba/fastjson

JSONScanner dateScanner = new JSONScanner(text);
if (dateScanner.scanISO8601DateIfMatch(false)) {
  Instant instant = dateScanner.getCalendar().toInstant();
  return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());

代码示例来源:origin: hibernate/hibernate-orm

return LocalDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() );

代码示例来源:origin: hibernate/hibernate-orm

return ZonedDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() ).toInstant();

代码示例来源:origin: hibernate/hibernate-orm

@Override
public <X> LocalDate wrap(X value, WrapperOptions options) {
  if ( value == null ) {
    return null;
  }
  if ( LocalDate.class.isInstance( value ) ) {
    return (LocalDate) value;
  }
  if ( Timestamp.class.isInstance( value ) ) {
    final Timestamp ts = (Timestamp) value;
    return LocalDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() ).toLocalDate();
  }
  if ( Long.class.isInstance( value ) ) {
    final Instant instant = Instant.ofEpochMilli( (Long) value );
    return LocalDateTime.ofInstant( instant, ZoneId.systemDefault() ).toLocalDate();
  }
  if ( Calendar.class.isInstance( value ) ) {
    final Calendar calendar = (Calendar) value;
    return LocalDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() ).toLocalDate();
  }
  if ( Date.class.isInstance( value ) ) {
    if ( java.sql.Date.class.isInstance( value ) ) {
      return ((java.sql.Date) value).toLocalDate();
    }
    else {
      return Instant.ofEpochMilli( ((Date) value).getTime() ).atZone( ZoneId.systemDefault() ).toLocalDate();
    }
  }
  throw unknownWrap( value.getClass() );
}

代码示例来源:origin: hibernate/hibernate-orm

return LocalDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() ).toLocalTime();

代码示例来源:origin: hibernate/hibernate-orm

return OffsetDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() );

代码示例来源:origin: hibernate/hibernate-orm

return OffsetTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() );

代码示例来源:origin: com.alibaba/fastjson

JSONScanner dateScanner = new JSONScanner(text);
if (dateScanner.scanISO8601DateIfMatch(false)) {
  Instant instant = dateScanner.getCalendar().toInstant();
  return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());

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

builder.setCalendar(doc.get(CalendarAnnotation.class).toInstant().toEpochMilli());
keysToSerialize.remove(CalendarAnnotation.class);

代码示例来源:origin: eclipse/smarthome

/**
 * @deprecated The constructor uses Calendar object hence it doesn't store time zone. A new constructor is
 *             available. Use {@link #DateTimeType(ZonedDateTime)} instead.
 *
 * @param calendar The Calendar object containing the time stamp.
 */
@Deprecated
public DateTimeType(Calendar calendar) {
  this.zonedDateTime = ZonedDateTime.ofInstant(calendar.toInstant(), TimeZone.getDefault().toZoneId())
      .withFixedOffsetZone();
}

代码示例来源:origin: DV8FromTheWorld/JDA

/**
 * Gets the creation-time of a JDA-entity by doing the reverse snowflake algorithm on its id.
 * This returns the creation-time of the actual entity on Discords side, not inside JDA.
 *
 * @param  entityId
 *         The id of the JDA entity where the creation-time should be determined for
 *
 * @return The creation time of the JDA entity as OffsetDateTime
 */
public static OffsetDateTime getCreationTime(long entityId)
{
  long timestamp = (entityId >>> TIMESTAMP_OFFSET) + DISCORD_EPOCH;
  Calendar gmt = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
  gmt.setTimeInMillis(timestamp);
  return OffsetDateTime.ofInstant(gmt.toInstant(), gmt.getTimeZone().toZoneId());
}

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

@Converter(autoApply=true)
public class ZonedDateTimeAttributeConverter implements AttributeConverter<ZonedDateTime, Calendar> {

  @Override
  public Calendar convertToDatabaseColumn(ZonedDateTime entityAttribute) {
    if (entityAttribute == null) {
      return null;
    }

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(entityAttribute.toInstant().toEpochMilli());
    calendar.setTimeZone(TimeZone.getTimeZone(entityAttribute.getZone()));
    return calendar;
  }

  @Override
  public ZonedDateTime convertToEntityAttribute(Calendar databaseColumn) {
    if (databaseColumn == null) {
      return null;
    }

    return ZonedDateTime.ofInstant(databaseColumn.toInstant(), databaseColumn.getTimeZone().toZoneId());
  }

}

代码示例来源:origin: openhab/openhab-core

/**
 * @deprecated The constructor uses Calendar object hence it doesn't store time zone. A new constructor is
 *             available. Use {@link #DateTimeType(ZonedDateTime)} instead.
 *
 * @param calendar The Calendar object containing the time stamp.
 */
@Deprecated
public DateTimeType(Calendar calendar) {
  this.zonedDateTime = ZonedDateTime.ofInstant(calendar.toInstant(), TimeZone.getDefault().toZoneId())
      .withFixedOffsetZone();
}

代码示例来源:origin: theotherp/nzbhydra2

@Override
  public Date nextExecutionTime(TriggerContext triggerContext) {
    Calendar nextExecutionTime = new GregorianCalendar();
    Date lastCompletionTime = runNow ? new Date() : triggerContext.lastCompletionTime();
    nextExecutionTime.setTime(lastCompletionTime != null ? lastCompletionTime : new Date());
    nextExecutionTime.add(Calendar.MILLISECOND, (int) getIntervalForTask(task));
    taskInformations.put(task, new TaskInformation(task.name(), lastCompletionTime != null ? lastCompletionTime.toInstant() : null, nextExecutionTime.toInstant()));
    return nextExecutionTime.getTime();
  }
});

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

protected ZonedDateTime toZonedDateTime(Calendar cal){
  if (cal instanceof GregorianCalendar){
    return ((GregorianCalendar)cal).toZonedDateTime();
  }
  ZoneId zoneId=cal.getTimeZone().toZoneId();
  return ZonedDateTime.ofInstant(cal.toInstant(), zoneId);
}

代码示例来源:origin: com.github.PhilippHeuer/events4j

/**
 * Register internal listeners
 */
private void registerInternalListener() {
  // Annotation-based EventListener
  onEvent(Event.class).subscribe(event -> {
    log.debug("Passed event [{}] to the method based annotation manager at {}.", event.getEventId(), event.getFiredAt().toInstant().toString());
    annotationEventManager.dispatch(event);
  });
}

代码示例来源:origin: com.vmware.dcp/dcp-common

@Test
public void testParseZonedDateTime() throws Exception {
  Calendar cal = Calendar.getInstance();
  cal.setTimeZone(TimeZone.getTimeZone("Australia/Sydney"));
  cal.set(2013, 4, 30, 23, 38, 27);
  cal.set(Calendar.MILLISECOND, 85);
  ZoneId zid = ZoneId.of("Australia/Sydney");
  ZonedDateTime expected = ZonedDateTime.ofInstant(cal.toInstant(), zid);
  ZonedDateTime actual = Utils.fromJson(
      "\"2013-05-30T23:38:27.085+10:00[Australia/Sydney]\"", ZonedDateTime.class);
  assertEquals(expected, actual);
}

代码示例来源:origin: vmware/xenon

@Test
public void testParseInstant() throws Exception {
  Calendar cal = Calendar.getInstance();
  cal.setTimeZone(TimeZone.getTimeZone("UTC"));
  cal.set(2013, 4, 30, 23, 38, 27);
  cal.set(Calendar.MILLISECOND, 85);
  Instant expected = cal.toInstant();
  Instant actual = Utils.fromJson("\"2013-05-30T23:38:27.085Z\"", Instant.class);
  assertEquals(expected, actual);
}

相关文章

微信公众号

最新文章

更多