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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With