Example usage for java.time Duration ofSeconds

List of usage examples for java.time Duration ofSeconds

Introduction

In this page you can find the example usage for java.time Duration ofSeconds.

Prototype

public static Duration ofSeconds(long seconds) 

Source Link

Document

Obtains a Duration representing a number of seconds.

Usage

From source file:Main.java

public static void main(String[] args) {
    Duration duration = Duration.ofSeconds(10);
    System.out.println(duration);
}

From source file:Main.java

public static void main(String[] args) {
    Duration d1 = Duration.ofSeconds(55);
    Duration d2 = Duration.ofSeconds(-17);

    Instant i1 = Instant.now();

    Instant i4 = i1.plus(d1);/*from w  w w  .  jav  a 2 s  . com*/
    Instant i5 = i1.minus(d2);

    Duration d3 = d1.plus(d2);
    System.out.println(d3);
}

From source file:Main.java

public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT, LocalTime.NOON);
    System.out.println(duration.getSeconds());

    System.out.println(Duration.ofSeconds(2340).equals(duration));
}

From source file:Main.java

public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT, LocalTime.NOON);
    System.out.println(duration.getSeconds());

    System.out.println(Duration.ofSeconds(2340).compareTo(duration));
}

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);/*w w  w  .j  av a 2  s . c  o 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. ja  v  a  2 s.c o  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 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:Main.java

public static void main(String[] args) {
    Clock utcClock = Clock.systemUTC();
    Clock defaultClock = Clock.systemDefaultZone();
    Clock offsetClock = Clock.offset(Clock.systemUTC(), Duration.ofHours(-5));

    ZoneId denverTimeZone = ZoneId.of("America/Denver");
    ZoneId newYorkTimeZone = ZoneId.of("America/New_York");
    ZoneId chicagoTimeZone = ZoneId.of("America/Chicago");
    ZoneId losAngelesTimeZone = ZoneId.of("America/Los_Angeles");

    Instant instant = Instant.now(defaultClock);
    Instant instant2 = Instant.now(utcClock);
    Instant instant3 = Instant.now(offsetClock);

    System.out.println(instant);/*from  w ww .  j  a  v  a2 s . c o m*/
    System.out.println(instant2);
    System.out.println(instant3.plus(Duration.ofSeconds(90)));
    System.out.println(instant3.atZone(newYorkTimeZone));
    System.out.println(instant3.atZone(chicagoTimeZone));
    System.out.println(instant3.atZone(denverTimeZone));
    System.out.println(instant3.atZone(losAngelesTimeZone));
}

From source file:playground.SseController.java

@RequestMapping("/sse/string")
Flux<String> string() {
    return Flux.interval(Duration.ofSeconds(1)).map(l -> "foo " + l);
}

From source file:playground.SseController.java

@RequestMapping("/sse/person")
Flux<Person> person() {/*from  ww w.jav  a  2 s.c o m*/
    return Flux.interval(Duration.ofSeconds(1)).map(l -> new Person(Long.toString(l), "foo", "bar"));
}