I know how much time has elapsed in second. From that how to get the start date and time.
For example, I know 1600 seconds has passed.
From that how I can find out what is the start date and time using JAVA API.
I know how much time has elapsed in second. From that how to get the start date and time.
For example, I know 1600 seconds has passed.
From that how I can find out what is the start date and time using JAVA API.
Create a Calendar
instance, add
-1600
seconds to it. Get the time
from it...
Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, -1600);
Date date = cal.getTime();
You can run the uptime
command using this example of how to start a process and read its output from Java. From there, it's just a matter of parsing the input.
You can do the difference between the current time and the uptime in milli-seconds.
long startTime = System.currentTimeMillis() - System.nanoTime()/1000000;
System.out.println(new Date(startTime));
in my case this prints
Wed Jul 24 22:33:55 BST 2013