-3

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.

Exploring
  • 3,269
  • 8
  • 42
  • 69
  • Read the documentation for [`Calendar`](http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html) or [`Date`](http://docs.oracle.com/javase/7/docs/api/java/util/Date.html). – jahroy Jul 24 '13 at 23:47

3 Answers3

2

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();
MadProgrammer
  • 336,120
  • 22
  • 219
  • 344
1

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.

Community
  • 1
  • 1
Mike Thomsen
  • 35,490
  • 10
  • 55
  • 80
0

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
Peter Lawrey
  • 513,304
  • 74
  • 731
  • 1,106