Get system start time from RuntimeMXBean in Java

Java 8Object Oriented ProgrammingProgramming

RuntimeMXBean in the management interface for the runtime system of the Java virtual machine.

RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean();

To get the system start time, use the getStartTime() method −

new Date(runtimeMX.getStartTime()

The following is an example −

Example

 Live Demo

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.Date;
public class Demo {
   public static void main(String args[]) throws Exception {
      RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean();
      System.out.println("System Start Time = "+new Date(runtimeMX.getStartTime()));
   }
}

Output

System Start Time = Mon Nov 26 07:03:19 UTC 2018
raja
Published on 26-Dec-2018 11:28:36
Advertisements