Java虚拟机的运行时系统的管理界面中的RuntimeMXBean。
RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean();
要获取系统启动时间,请使用getStartTime()
方法-
new Date(runtimeMX.getStartTime()
以下是一个例子-
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())); } }
输出结果
System Start Time = Mon Nov 26 07:03:19 UTC 2018