How do I get the start time of a JVM?


import java.util.Date;

public class GetStartTime {
    public static void main(String[] args) {
        RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();

        // Returns the start time of the Java virtual machine in 
        // milliseconds. This method returns the approximate time 
        // when the Java virtual machine started.
        long startTime = bean.getStartTime();
        Date startDate = new Date(startTime);
        System.out.println("Start Time = " + startTime);
        System.out.println("Start Date = " + startDate);

The result of the code snippet above:

Start Time = 1513234850942
Start Date = Thu Dec 14 15:00:50 WITA 2017

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.