List of usage examples for java.time.temporal ChronoUnit SECONDS
ChronoUnit SECONDS
To view the source code for java.time.temporal ChronoUnit SECONDS.
Click Source Link
From source file:Main.java
public static void main(String[] args) { LocalTime l = LocalTime.now(); LocalTime s = l.minus(1000, ChronoUnit.SECONDS); System.out.println(s);/*w ww . j a va2s . co m*/ }
From source file:Main.java
public static void main(String[] args) { Duration duration = Duration.between(LocalTime.MIDNIGHT, LocalTime.NOON); System.out.println(duration.get(ChronoUnit.SECONDS)); }
From source file:Main.java
public static void main(String[] args) { // Instant is useful for generating a time stamp to represent machine time. Instant timestamp = Instant.now(); // How many seconds have occurred since the beginning of the Java epoch. long secondsFromEpoch = Instant.ofEpochSecond(0L).until(Instant.now(), ChronoUnit.SECONDS); System.out.println(secondsFromEpoch); }
From source file:org.openmastery.time.LocalDateTimeService.java
public static LocalDateTime nowTruncateToSeconds() { return LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS); }
From source file:Main.java
public static ChronoUnit convert(TimeUnit tu) { if (tu == null) { return null; }// www.j ava 2 s . c om 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:fr.ffremont.caching.ExpireCache.java
@GET @Path("mix10sec") public Response mix10sec() { Date expires = Date.from(Instant.now().plus(10, ChronoUnit.SECONDS)); CacheControl cache = new CacheControl(); cache.setMaxAge(60);// w w w. j ava2 s. c om LOG.info("Retour du contenu"); return Response.ok("En cache pendant 10sec").cacheControl(cache).expires(expires).build(); }
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)); }//from ww w . ja v a 2 s . co m } Activator.setValue(task, Activator.TICK, now.toString()); Activator.setValue(task, Activator.START, now.toString()); }
From source file:com.pepaproch.gtswsdl.client.RateLimitTest.java
@Test public void testCOnsumeSLotAsync() { RateLimit rate = new RateLimit(5, 10, ChronoUnit.SECONDS); ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(10); final AtomicInteger cc = new AtomicInteger(0); Instant start = Instant.now(); final Instant[] end = new Instant[1]; Runnable r = () -> {//from www . ja v a 2s .co m for (int i = 0; i < 21; i++) { addTask(cc, scheduler, rate, end); } }; Runnable r1 = () -> { for (int i = 0; i < 9; i++) { addTask(cc, scheduler, rate, end); } }; r1.run(); r.run(); try { scheduler.awaitTermination(5, TimeUnit.SECONDS); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(Duration.between(start, end[0]).toMillis()); }
From source file:com.teradata.benchto.driver.graphite.GraphiteProperties.java
public Duration getGraphiteMetricsDelay() { return Duration.of(graphiteMetricsDelaySeconds, ChronoUnit.SECONDS); }
From source file:Jimbo.Cheerlights.MQTTListener.java
/** * Receive an MQTT message./* w w w. j av a 2 s . co m*/ * * @param topic The topic it's on * @param message The message itself */ @Override public void receive(String topic, String message) { try { JSONObject j = new JSONObject(message); final Instant instant = Instant.ofEpochMilli(j.getLong("sent")).truncatedTo(ChronoUnit.SECONDS); final LocalDateTime stamp = LocalDateTime.ofInstant(instant, ZONE); final String when = stamp.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME); LOG.log(Level.INFO, "{0} (@{1}) sent {2}: {3}", new Object[] { j.getString("name"), j.getString("screen"), when, j.getString("text") }); target.update(j.getInt("colour")); } catch (JSONException | IOException e) { LOG.log(Level.WARNING, "Unable to parse: \"{0}\": {1}", new Object[] { message, e.getLocalizedMessage() }); } }