org.threeten.bp.Instant.toEpochMilli()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(125)

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

Instant.toEpochMilli介绍

[英]Converts this instant to the number of milliseconds from the epoch of 1970-01-01T00:00:00Z.

If this instant represents a point on the time-line too far in the future or past to fit in a long milliseconds, then an exception is thrown.

If this instant has greater than millisecond precision, then the conversion will drop any excess precision information as though the amount in nanoseconds was subject to integer division by one million.
[中]将此瞬间转换为从1970-01-01T00:00:00Z开始的毫秒数。
如果此瞬间表示时间线上的某个点在未来或过去太远,无法容纳很长的毫秒,则会引发异常。
如果该瞬间的精度大于毫秒,则转换将删除任何多余的精度信息,就像以纳秒为单位的量被整数除以一百万一样。

代码示例

代码示例来源:origin: googleapis/google-cloud-java

@Override
public long getDelay(TimeUnit unit) {
 return unit.convert(
   getScheduledTime().toEpochMilli() - clock.millisTime(), TimeUnit.MILLISECONDS);
}

代码示例来源:origin: googleapis/google-cloud-java

static ChangeRequestInfo fromPb(Change pb) {
 Builder builder = newBuilder();
 if (pb.getId() != null) {
  builder.setGeneratedId(pb.getId());
 }
 if (pb.getStartTime() != null) {
  builder.setStartTime(
    DateTimeFormatter.ISO_DATE_TIME.parse(pb.getStartTime(), Instant.FROM).toEpochMilli());
 }
 if (pb.getStatus() != null) {
  // we are assuming that status indicated in pb is a lower case version of the enum name
  builder.setStatus(ChangeRequest.Status.valueOf(pb.getStatus().toUpperCase()));
 }
 if (pb.getDeletions() != null) {
  builder.setDeletions(Lists.transform(pb.getDeletions(), RecordSet.FROM_PB_FUNCTION));
 }
 if (pb.getAdditions() != null) {
  builder.setAdditions(Lists.transform(pb.getAdditions(), RecordSet.FROM_PB_FUNCTION));
 }
 return builder.build();
}

代码示例来源:origin: googleapis/google-cloud-java

static ZoneInfo fromPb(ManagedZone pb) {
 Builder builder = new BuilderImpl(pb.getName());
 if (pb.getDescription() != null) {
  builder.setDescription(pb.getDescription());
 }
 if (pb.getDnsName() != null) {
  builder.setDnsName(pb.getDnsName());
 }
 if (pb.getId() != null) {
  builder.setGeneratedId(pb.getId().toString());
 }
 if (pb.getNameServers() != null) {
  builder.setNameServers(pb.getNameServers());
 }
 if (pb.getNameServerSet() != null) {
  builder.setNameServerSet(pb.getNameServerSet());
 }
 if (pb.getCreationTime() != null) {
  builder.setCreationTimeMillis(
    DATE_TIME_FORMATTER.parse(pb.getCreationTime(), Instant.FROM).toEpochMilli());
 }
 return builder.build();
}

代码示例来源:origin: googleapis/google-cloud-java

static ProjectInfo fromPb(com.google.api.services.cloudresourcemanager.model.Project projectPb) {
  Builder builder =
    newBuilder(projectPb.getProjectId()).setProjectNumber(projectPb.getProjectNumber());
  if (projectPb.getName() != null && !projectPb.getName().equals("Unnamed")) {
   builder.setName(projectPb.getName());
  }
  if (projectPb.getLabels() != null) {
   builder.setLabels(projectPb.getLabels());
  }
  if (projectPb.getLifecycleState() != null) {
   builder.setState(State.valueOf(projectPb.getLifecycleState()));
  }
  if (projectPb.getCreateTime() != null) {
   builder.setCreateTimeMillis(
     DATE_TIME_FORMATTER.parse(projectPb.getCreateTime(), Instant.FROM).toEpochMilli());
  }
  if (projectPb.getParent() != null) {
   builder.setParent(ResourceId.fromPb(projectPb.getParent()));
  }
  return builder.build();
 }
}

代码示例来源:origin: ThreeTen/threetenbp

@Override
public long millis() {
  return instant.toEpochMilli();
}
@Override

代码示例来源:origin: org.threeten/threetenbp

@Override
public long millis() {
  return instant.toEpochMilli();
}
@Override

代码示例来源:origin: com.github.joschi.jackson/jackson-datatype-threetenbp

@Override
  public long applyAsLong(Instant value) {
    return value.toEpochMilli();
  }
},

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Converts an {@code Instant} to a {@code java.util.Date}.
 * <p>
 * Fractions of the instant smaller than milliseconds will be dropped.
 *
 * @param instant  the instant, not null
 * @return the util date, not null
 * @throws IllegalArgumentException if the conversion fails
 */
public static Date toDate(Instant instant) {
  try {
    return new Date(instant.toEpochMilli());
  } catch (ArithmeticException ex) {
    throw new IllegalArgumentException(ex);
  }
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Converts an {@code Instant} to a {@code java.util.Date}.
 * <p>
 * Fractions of the instant smaller than milliseconds will be dropped.
 *
 * @param instant  the instant, not null
 * @return the util date, not null
 * @throws IllegalArgumentException if the conversion fails
 */
public static Date toDate(Instant instant) {
  try {
    return new Date(instant.toEpochMilli());
  } catch (ArithmeticException ex) {
    throw new IllegalArgumentException(ex);
  }
}

代码示例来源:origin: com.github.joschi.jackson/jackson-datatype-threetenbp

@Override
  public long applyAsLong(ZonedDateTime dt) {
    return dt.toInstant().toEpochMilli();
  }
},

代码示例来源:origin: jeffdcamp/dbtools-android

@Nullable
public static Long localDateTimeToLongUtc(@Nullable LocalDateTime d) {
  if (d == null) {
    return null;
  }
  return d.toInstant(ZoneOffset.UTC).toEpochMilli();
}

代码示例来源:origin: com.github.joschi.jackson/jackson-datatype-threetenbp

@Override
  public long applyAsLong(OffsetDateTime dt) {
    return dt.toInstant().toEpochMilli();
  }
},

代码示例来源:origin: Ullink/simple-slack-api

private String convertDateToSlackTimestamp(ZonedDateTime date) {
  return (date.toInstant().toEpochMilli() / 1000) + ".123456";
}

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

public long getMillisFromUnix() {
  return getValue().toEpochMilli();
}

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

public long getMillisFromUnix() {
  return getValue().toEpochMilli();
}

代码示例来源:origin: gotify/android

public static String dateToRelative(OffsetDateTime data) {
  long time = data.toInstant().toEpochMilli();
  long now = System.currentTimeMillis();
  return DateUtils.getRelativeTimeSpanString(time, now, DateUtils.MINUTE_IN_MILLIS)
      .toString();
}

代码示例来源:origin: apache/servicemix-bundles

@Nonnull
  @Override
  public java.time.Instant convert(LocalDateTime source) {
    return java.time.Instant.ofEpochMilli(source.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli());
  }
}

代码示例来源:origin: jeffdcamp/dbtools-android

@Nullable
public static Long localDateTimeToLong(@Nullable LocalDateTime d) {
  if (d == null) {
    return null;
  }
  return d.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
}

代码示例来源:origin: jeffdcamp/dbtools-android

@Test
public void testNow() throws Exception {
  System.out.println("Date:   " + new Date().getTime());
  System.out.println("Joda:   " + DateTime.now().getMillis());
  System.out.println("JSR310: " + Instant.now().toEpochMilli());
}

代码示例来源:origin: com.torodb.kvdocument/mongo-converter

@Override
public BsonValue visit(DateValue value, Void arg) {
  Instant instant = value.getValue().atStartOfDay().toInstant(ZoneOffset.UTC);
  return new BsonDateTime(instant.toEpochMilli());
}

相关文章