Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding time to calendar [duplicate]

Tags:

java

Possible Duplicate:
How to subtract X days from a date using Java calendar?

This should be fairly simple to answer, but I want to know: if you, for example, added 50 seconds to a Calendar, and the current seconds were 20, would it add 1 minute and set the seconds to 10, or set seconds to 70? Here's a bit of code to better demonstrate what I mean:

Calendar cal;  
public void test(){  
cal.add(Calendar.SECOND, 50);  
}

So, let's say that when that code ran, the current second was 20 and the current minute was 10. Would it go to 11 minutes, 10 seconds, or 10 minutes, 70 seconds? Thanks in advance.

like image 505
Theway2cool1 Avatar asked Oct 08 '12 07:10

Theway2cool1


1 Answers

I neither try it, but I expect it will pass to 1 minute and 10 seconds.

...now i tried and obviously is confirmed :

public class Test {

public static void main(String[] args) {
    Calendar cal = GregorianCalendar.getInstance();
    System.out.println("Minutes : "+ cal.get(Calendar.MINUTE));
    System.out.println("Seconds :" + cal.get(Calendar.SECOND));
    cal.add(Calendar.SECOND, 50);
    System.out.println("Minutes : "+ cal.get(Calendar.MINUTE));
    System.out.println("Seconds :" + cal.get(Calendar.SECOND));
}

}

Printed to my console :

Minutes : 11
Seconds :33
Minutes : 12
Seconds :23
like image 162
obe6 Avatar answered Sep 28 '22 02:09

obe6