-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
  • 2,493
  • 11
  • 56
  • 97
  • 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
  • 343,457
  • 22
  • 230
  • 366
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
  • 36,828
  • 10
  • 60
  • 83
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
  • 525,659
  • 79
  • 751
  • 1,130