首页javadateJava Data Type - 如何get自Java时代开始以来发生了多少秒

Java Data Type - 如何get自Java时代开始以来发生了多少秒

我们想知道如何get自Java时代开始以来发生了多少秒。
import java.time.Instant;
import java.time.temporal.ChronoUnit;

public class Main {

  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);
  }
}