Reputation: 3852
I want to get the actuel timestamp and add 5 seconds to it . I tried this code
java.util.Calendar cal = new java.util.GregorianCalendar(2007, 9 - 1, 23);
// Current time would be....
java.util.Calendar cal2 = java.util.Calendar.getInstance();
System.out.println("Instance before : "+ cal2.getTimeInMillis());
cal2.add(java.util.Calendar.SECOND, 5);
System.out.println("Instance after : "+ cal2.getTimeInMillis());
Output
Instance before : 1390785186301 Instance after : 1390785191301
I don't think that this output is a correct timestamp. I tried the two result in an online website and it work only if I delete the last 3 numbers 1390785186 , and the second one is +5 milliseconds
Upvotes: 0
Views: 112
Reputation: 41188
The website you looked at is using unix time which is SECONDS since 1970. Java uses MILLISECONDS since 1970. Java time is more precise but you need to divide by 1000 to get seconds.
Upvotes: 1