Duration getSeconds() example

Description

Duration getSeconds() gets the number of seconds in this duration. The length of the duration is stored using two fields - seconds and nanoseconds.

Syntax

getSeconds has the following syntax.


public long getSeconds()

Example

The following example shows how to use getSeconds.


import java.time.Duration;
import java.time.LocalTime;
/*  www  . ja v  a2 s.c om*/
public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
    System.out.println(duration.getSeconds());

  }
}

The code above generates the following result.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset