Syntax error Get system start time from RuntimeMXBean in Java

Get system start time from RuntimeMXBean in Java



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
Updated on: 2019-07-30T22:30:24+05:30

354 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements