@Override public long getDelay(TimeUnit unit) { return unit.convert( getScheduledTime().toEpochMilli() - clock.millisTime(), TimeUnit.MILLISECONDS); }
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(); }
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(); }
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(); } }
@Override public long millis() { return instant.toEpochMilli(); } @Override
@Override public long millis() { return instant.toEpochMilli(); } @Override
@Override public long applyAsLong(Instant value) { return value.toEpochMilli(); } },
/** * 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); } }
/** * 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); } }
@Override public long applyAsLong(ZonedDateTime dt) { return dt.toInstant().toEpochMilli(); } },
@Nullable public static Long localDateTimeToLongUtc(@Nullable LocalDateTime d) { if (d == null) { return null; } return d.toInstant(ZoneOffset.UTC).toEpochMilli(); }
@Override public long applyAsLong(OffsetDateTime dt) { return dt.toInstant().toEpochMilli(); } },
private String convertDateToSlackTimestamp(ZonedDateTime date) { return (date.toInstant().toEpochMilli() / 1000) + ".123456"; }
public long getMillisFromUnix() { return getValue().toEpochMilli(); }
public long getMillisFromUnix() { return getValue().toEpochMilli(); }
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(); }
@Nonnull @Override public java.time.Instant convert(LocalDateTime source) { return java.time.Instant.ofEpochMilli(source.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli()); } }
@Nullable public static Long localDateTimeToLong(@Nullable LocalDateTime d) { if (d == null) { return null; } return d.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); }
@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()); }
@Override public BsonValue visit(DateValue value, Void arg) { Instant instant = value.getValue().atStartOfDay().toInstant(ZoneOffset.UTC); return new BsonDateTime(instant.toEpochMilli()); }