List of usage examples for java.time Duration between
public static Duration between(Temporal startInclusive, Temporal endExclusive)
From source file:Main.java
public static void main(String[] args) { Duration duration = Duration.ofDays(33); //seconds or nanos Duration duration1 = Duration.ofHours(33); //seconds or nanos Duration duration2 = Duration.ofMillis(33); //seconds or nanos Duration duration3 = Duration.ofMinutes(33); //seconds or nanos Duration duration4 = Duration.ofNanos(33); //seconds or nanos Duration duration5 = Duration.ofSeconds(33); //seconds or nanos Duration duration6 = Duration.between(LocalDate.of(2012, 11, 11), LocalDate.of(2013, 1, 1)); System.out.println(duration6.getSeconds()); System.out.println(duration.getNano()); System.out.println(duration.getSeconds()); }
From source file:org.sansdemeure.zenindex.main.Main.java
public static void main(String[] args) { Instant start = Instant.now(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ServiceConfig.class); ctx.refresh();/*from w w w . ja va 2 s . c o m*/ BatchService batch = (BatchService) ctx.getBean("batchService"); batch.start(new File(args[0])); ctx.close(); Instant end = Instant.now(); logger.info("Duration of batch {}", Duration.between(start, end)); }
From source file:com.example.IdGenerator.java
public long generateLong() { final LocalDateTime now = LocalDateTime.now(clock); final Duration duration = Duration.between(BASE, now); final int high = (int) duration.getSeconds(); final int low = duration.getNano(); final byte[] hbs = ByteBuffer.allocate(4).putInt(high).array(); final byte[] lbs = ByteBuffer.allocate(4).putInt(low).array(); final byte[] bytes = new byte[8]; System.arraycopy(hbs, 0, bytes, 0, 4); System.arraycopy(lbs, 0, bytes, 4, 4); final ByteBuffer buffer = ByteBuffer.allocate(8).put(bytes, 0, 8); buffer.flip();// w w w .j a v a 2s . co m return buffer.getLong(); }
From source file:mServer.tool.MserverDatumZeit.java
public static long getSecondsUntilNextDay() { // now/*from w ww .j a v a2s. c o m*/ LocalDateTime now = LocalDateTime.now(); // tomorrow 0:00 LocalDateTime future = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).plusDays(1L); Duration duration = Duration.between(now, future); return duration.getSeconds(); }
From source file:fr.inria.atlanmod.neoemf.benchmarks.query.Query.java
default V callWithTime() throws Exception { V result;//from w ww. jav a 2 s . c o m Instant begin = Instant.now(); result = callWithResult(); Instant end = Instant.now(); log.info("Time spent: {}", Duration.between(begin, end)); return result; }
From source file:com.mgmtp.perfload.perfalyzer.util.TestMetadata.java
public static TestMetadata create(final String rawResultsDir, final Properties properties) { ZonedDateTime start = ZonedDateTime.parse(properties.getProperty("test.start"), DateTimeFormatter.ISO_OFFSET_DATE_TIME); ZonedDateTime end = ZonedDateTime.parse(properties.getProperty("test.finish"), DateTimeFormatter.ISO_OFFSET_DATE_TIME); String duration = DurationFormatUtils.formatDurationHMS(Duration.between(start, end).toMillis()); String operationsString = properties.getProperty("operations"); Set<String> operations = newTreeSet(on(',').trimResults().split(operationsString)); return new TestMetadata(start, end, duration, properties.getProperty("test.file"), rawResultsDir, properties.getProperty("perfload.implementation.version"), properties.getProperty("test.comment"), operations);//from ww w .j a v a 2 s . com }
From source file:org.openmhealth.data.generator.service.TimestampedValueGroupGenerationServiceImpl.java
@Override public Iterable<TimestampedValueGroup> generateValueGroups(MeasureGenerationRequest request) { ExponentialDistribution interPointDurationDistribution = new ExponentialDistribution( request.getMeanInterPointDuration().getSeconds()); long totalDurationInS = Duration.between(request.getStartDateTime(), request.getEndDateTime()).getSeconds(); OffsetDateTime effectiveDateTime = request.getStartDateTime(); List<TimestampedValueGroup> timestampedValueGroups = new ArrayList<>(); do {//from w ww . j a v a 2 s . c o m effectiveDateTime = effectiveDateTime.plus((long) interPointDurationDistribution.sample(), SECONDS); if (!effectiveDateTime.isBefore(request.getEndDateTime())) { break; } if (request.isSuppressNightTimeMeasures() != null && request.isSuppressNightTimeMeasures() && (effectiveDateTime.getHour() >= NIGHT_TIME_START_HOUR || effectiveDateTime.getHour() < NIGHT_TIME_END_HOUR)) { continue; } TimestampedValueGroup valueGroup = new TimestampedValueGroup(); valueGroup.setTimestamp(effectiveDateTime); double trendProgressFraction = (double) Duration.between(request.getStartDateTime(), effectiveDateTime) .getSeconds() / totalDurationInS; for (Map.Entry<String, BoundedRandomVariableTrend> trendEntry : request.getTrends().entrySet()) { String key = trendEntry.getKey(); BoundedRandomVariableTrend trend = trendEntry.getValue(); double value = trend.nextValue(trendProgressFraction); valueGroup.setValue(key, value); } timestampedValueGroups.add(valueGroup); } while (true); return timestampedValueGroups; }
From source file:io.mandrel.metrics.MetricsService.java
public Timeserie serie(String name) { Timeserie serie = metricsRepository.serie(name); LocalDateTime now = LocalDateTime.now(); LocalDateTime minus4Hours = now.withMinute(0).withSecond(0).withNano(0).minusHours(4); LocalDateTime firstTime = CollectionUtils.isNotEmpty(serie) && serie.first() != null && serie.first().getTime().isBefore(minus4Hours) ? serie.first().getTime() : minus4Hours; LocalDateTime lastTime = now; Set<Data> results = LongStream.range(0, Duration.between(firstTime, lastTime).toMinutes()) .mapToObj(minutes -> firstTime.plusMinutes(minutes)).map(time -> Data.of(time, Long.valueOf(0))) .collect(TreeSet::new, TreeSet::add, (left, right) -> { left.addAll(right);//from www .ja v a2 s . co m }); Timeserie serieWithBlank = new Timeserie(); serieWithBlank.addAll(results); serieWithBlank.addAll(serie); return serieWithBlank; }
From source file:se.sawano.java.text.PerformanceIT.java
private Duration using(final Comparator<CharSequence> comparator) { final Instant start = now(); stringsToSort.sort(comparator);/*from w w w .j ava2 s. c o m*/ return Duration.between(start, now()); }
From source file:de.kaiserpfalzEdv.commons.jee.spring.ServiceLogging.java
@Around("execution(* de.kaiserpfalzEdv..service..*Impl.*(..))") public Object updateMDC(ProceedingJoinPoint joinPoint) throws Throwable { String id = retrieveIdFromMDCOrGenerateNewUUID(joinPoint); MDC.put("id", id); Object result;/*from www . j a v a2 s . c om*/ if (oplog.isInfoEnabled()) { String serviceName = retrieveMethodNameFromSignature(joinPoint); OffsetDateTime start = OffsetDateTime.now(UTC); oplog.info("Service '{}' started. id={}, start={}", serviceName, id, start); result = joinPoint.proceed(); OffsetDateTime end = OffsetDateTime.now(UTC); oplog.info("Service '{}' ended. id={}, start={}, duration={}", retrieveMethodNameFromSignature(joinPoint), id, start, Duration.between(start, end)); } else { result = joinPoint.proceed(); } MDC.remove("id"); return result; }