首页javadateJava Data Type - 如何得到秒,分两秒之间的瞬间

Java Data Type - 如何得到秒,分两秒之间的瞬间

我们想知道如何得到秒,分两秒之间的瞬间。
import java.time.Duration;
import java.time.Instant;

public class Main {
  public static void main(String[] args) {
    Instant firstInstant = Instant.ofEpochSecond(1294881180); 
    Instant secondInstant = Instant.ofEpochSecond(1294708260); 

    Duration between = Duration.between(firstInstant, secondInstant);

    System.out.println(between);
    
    long seconds = between.getSeconds();

    long absoluteResult = between.abs().toMinutes();

  }
}