Java Calendar SECOND

Syntax

Calendar.SECOND has the following syntax.

public static final int SECOND

Example

In the following code shows how to use Calendar.SECOND field.


import java.util.Calendar;
//  w  w w . j  ava  2s . c  om
public class Main {
  public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    // add seconds to current date
    now.add(Calendar.SECOND, 500);
    System.out.println("adding 500 seconds : ");
    System.out.println(now.get(Calendar.MINUTE) + ":"
        + now.get(Calendar.SECOND));

    // adding minus value
    now = Calendar.getInstance();
    now.add(Calendar.SECOND, -500);
    System.out.println("adding -500 seconds: ");
    System.out.println(now.get(Calendar.MINUTE) + ":"
        + now.get(Calendar.SECOND));
  }
}

The output: