package org.nhooo.example.management; import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.util.Date; public class GetStartTime { public static void main(String[] args) { RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); // 返回Java虚拟机的开始时间,其中 //毫秒。此方法返回大概时间 // Java虚拟机启动时。 long startTime = bean.getStartTime(); Date startDate = new Date(startTime); System.out.println("Start Time = " + startTime); System.out.println("Start Date = " + startDate); } }
上面的代码片段的结果:
Start Time = 1513234850942 Start Date = Thu Dec 14 15:00:50 WITA 2017