List of usage examples for java.time.temporal ChronoUnit MILLIS
ChronoUnit MILLIS
To view the source code for java.time.temporal ChronoUnit MILLIS.
Click Source Link
From source file:Main.java
public static void main(String[] args) { Instant t1 = Instant.now(); long hours = 2; long minutes = 30; Instant t2 = t1.plus(hours, ChronoUnit.HOURS).plus(minutes, ChronoUnit.MINUTES); Duration gap = Duration.ofSeconds(13); Instant later = t1.plus(gap); System.out.println(later);// www . ja va 2 s . co m System.out.println(ChronoUnit.MILLIS.between(t1, t2)); }
From source file:Main.java
public static void main(String[] args) { Instant t1 = Instant.now(); Instant t2 = Instant.now().plusSeconds(12); long nanos = Duration.between(t1, t2).toNanos(); System.out.println(nanos);/*from w w w .j a v a 2 s. co m*/ Duration gap = Duration.ofSeconds(13); // 12000000000 Instant later = t1.plus(gap); System.out.println(t1); // 2014-07-02T19:55:00.956Z System.out.println(later); // 2014-07-02T19:55:13.956Z System.out.println(ChronoUnit.MILLIS.between(t1, t2)); // 12000 }
From source file:Main.java
public static ChronoUnit convert(TimeUnit tu) { if (tu == null) { return null; }//from ww w.j a va 2 s. c o m switch (tu) { case DAYS: return ChronoUnit.DAYS; case HOURS: return ChronoUnit.HOURS; case MINUTES: return ChronoUnit.MINUTES; case SECONDS: return ChronoUnit.SECONDS; case MICROSECONDS: return ChronoUnit.MICROS; case MILLISECONDS: return ChronoUnit.MILLIS; case NANOSECONDS: return ChronoUnit.NANOS; default: assert false : "there are no other TimeUnit ordinal values"; return null; } }
From source file:net.resheim.eclipse.timekeeper.internal.TaskActivationListener.java
@Override public void preTaskActivated(ITask task) { LocalDateTime now = LocalDateTime.now(); String startString = Activator.getValue(task, Activator.START); String tickString = Activator.getValue(task, Activator.TICK); if (startString != null) { LocalDateTime ticked = LocalDateTime.parse(tickString); LocalDateTime stopped = LocalDateTime.now(); long seconds = ticked.until(stopped, ChronoUnit.SECONDS); String time = DurationFormatUtils.formatDuration(seconds * 1000, "H:mm", true); boolean confirm = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Add elapsed time?", "Work was already started and task was last updated on " + ticked.format(DateTimeFormatter.ofPattern("EEE e, HH:mm", Locale.US)) + ". Continue and add the elapsed time since (" + time + ") to the task total?"); if (confirm) { Activator.accumulateTime(task, startString, ticked.until(LocalDateTime.now(), ChronoUnit.MILLIS)); }/*ww w.j av a2s .c om*/ } Activator.setValue(task, Activator.TICK, now.toString()); Activator.setValue(task, Activator.START, now.toString()); }
From source file:io.coala.time.TimeSpan.java
/** * {@link TimeSpan} static factory method * //from w w w . ja v a 2 s . c om * @param temporal a JSR-310 {@link TemporalAmount} */ public static TimeSpan of(final TemporalAmount temporal) { return new TimeSpan( BigDecimal.valueOf(temporal.get(ChronoUnit.NANOS)) .add(BigDecimal.valueOf(temporal.get(ChronoUnit.MILLIS)).multiply(BigDecimal.TEN.pow(6))), Units.NANOS); }
From source file:com.netflix.genie.web.configs.GenieApiAutoConfiguration.java
/** * Get RestTemplate for calling between Genie nodes. * * @param httpProperties The properties related to Genie's HTTP client configuration * @param restTemplateBuilder The Spring REST template builder to use * @return The rest template to use/* w ww .j av a 2s .c o m*/ */ @Bean @ConditionalOnMissingBean(name = "genieRestTemplate") public RestTemplate genieRestTemplate(final HttpProperties httpProperties, final RestTemplateBuilder restTemplateBuilder) { return restTemplateBuilder .setConnectTimeout(Duration.of(httpProperties.getConnect().getTimeout(), ChronoUnit.MILLIS)) .setReadTimeout(Duration.of(httpProperties.getRead().getTimeout(), ChronoUnit.MILLIS)).build(); }
From source file:com.teradata.benchto.driver.listeners.BenchmarkServiceExecutionListener.java
private void checkClocksSync() { long timeBefore = System.currentTimeMillis(); long serviceTime = benchmarkServiceClient.getServiceCurrentTime().toEpochMilli(); long timeAfter = System.currentTimeMillis(); long driftApproximation = Math.abs(LongMath.mean(timeBefore, timeAfter) - serviceTime); long approximationPrecision = timeAfter - LongMath.mean(timeBefore, timeAfter); Duration driftLowerBound = Duration.of(driftApproximation - approximationPrecision, ChronoUnit.MILLIS); if (driftLowerBound.compareTo(MAX_CLOCK_DRIFT) > 1) { throw new RuntimeException( format("Detected driver and service clocks drift of at least %s, assumed sane maximum is %s", driftLowerBound, MAX_CLOCK_DRIFT)); }/*from w w w . ja v a2s .c o m*/ }
From source file:com.teradata.benchto.driver.execution.ExecutionSynchronizer.java
/** * Executes {@code callable} when time comes. The {@code callable} gets executed immediately, without * offloading to a backghround thread, if execution time requested has already passed. *///from w w w . jav a2 s . co m public <T> CompletableFuture<T> execute(Instant when, Callable<T> callable) { if (!Instant.now().isBefore(when)) { // Run immediately. try { return completedFuture(callable.call()); } catch (Exception e) { CompletableFuture<T> future = new CompletableFuture<>(); future.completeExceptionally(e); return future; } } long delay = Instant.now().until(when, ChronoUnit.MILLIS); CompletableFuture<T> future = new CompletableFuture<>(); executorService.schedule(() -> { try { future.complete(callable.call()); } catch (Throwable e) { future.completeExceptionally(e); throw e; } return null; }, delay, MILLISECONDS); return future; }
From source file:com.nextdoor.bender.ipc.http.HttpTransport.java
public void sendBatch(byte[] raw) throws TransportException { /*/*w w w. jav a 2 s. c o m*/ * Wrap the call with retry logic to avoid intermittent ES issues. */ Callable<HttpResponse> callable = () -> { HttpResponse resp; String responseString = null; HttpPost httpPost = new HttpPost(this.url); /* * Do the call, read response, release connection so it is available for use again, and * finally check the response. */ try { if (this.useGzip) { resp = sendBatchCompressed(httpPost, raw); } else { resp = sendBatchUncompressed(httpPost, raw); } try { responseString = EntityUtils.toString(resp.getEntity()); } catch (ParseException | IOException e) { throw new TransportException( "http transport call failed because " + resp.getStatusLine().getReasonPhrase()); } } finally { /* * Always release connection otherwise it blocks future requests. */ httpPost.releaseConnection(); } checkResponse(resp, responseString); return resp; }; RetryConfig config = new RetryConfigBuilder().retryOnSpecificExceptions(TransportException.class) .withMaxNumberOfTries(this.retries + 1).withDelayBetweenTries(this.retryDelayMs, ChronoUnit.MILLIS) .withExponentialBackoff().build(); try { new CallExecutor(config).execute(callable); } catch (RetriesExhaustedException ree) { logger.warn("transport failed after " + ree.getCallResults().getTotalTries() + " tries."); throw new TransportException(ree.getCallResults().getLastExceptionThatCausedRetry()); } catch (UnexpectedException ue) { throw new TransportException(ue); } }
From source file:msi.gama.util.GamaDate.java
public GamaDate(final IScope scope, final double val) { this(scope, scope.getSimulation().getStartingDate().plus(val * 1000, ChronoUnit.MILLIS)); }