How do I get the start time of a JVM?

package org.kodejava.example.lang.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();

        //
        // 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);
    }
}
Wayan Saryada

Wayan Saryada

A programmer, runner, recreational diver, currently living in the island of Bali, Indonesia. Mostly programming in Java, creating web based application with Spring Framework, JPA, etc. If you need help on Java programming you can hire me on Fiverr.
Wayan Saryada

Leave a Reply