Example usage for java.util Calendar SECOND

List of usage examples for java.util Calendar SECOND

Introduction

In this page you can find the example usage for java.util Calendar SECOND.

Prototype

int SECOND

To view the source code for java.util Calendar SECOND.

Click Source Link

Document

Field number for get and set indicating the second within the minute.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan"));
    japanCal.set(Calendar.HOUR_OF_DAY, 10); // 0..23
    japanCal.set(Calendar.MINUTE, 0);
    japanCal.set(Calendar.SECOND, 0);

    Calendar local = new GregorianCalendar();
    local.setTimeInMillis(japanCal.getTimeInMillis());
    int hour = local.get(Calendar.HOUR); // 5
    int minutes = local.get(Calendar.MINUTE); // 0
    int seconds = local.get(Calendar.SECOND); // 0
    boolean am = local.get(Calendar.AM_PM) == Calendar.AM; // false
}

From source file:Main.java

public static void main(String[] args) {
    Date myDate;/*  w  w w.  j a  va  2s .c o  m*/
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MONTH, 9);
    cal.set(Calendar.DATE, 24);
    cal.set(Calendar.YEAR, 2013);
    cal.set(Calendar.HOUR, 13);
    cal.set(Calendar.MINUTE, 45);
    cal.set(Calendar.SECOND, 52);
    myDate = cal.getTime();
    System.out.println(myDate);
}

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();

    System.out.println("Current full date time is : " + (now.get(Calendar.MONTH) + 1) + "-"
            + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR) + " " + now.get(Calendar.HOUR_OF_DAY) + ":"
            + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND) + "." + now.get(Calendar.MILLISECOND));
}

From source file:Main.java

public static void main(String[] args) {
    Calendar calendar = Calendar.getInstance();

    // 15-04-2012
    calendar.set(Calendar.DAY_OF_MONTH, 15);
    calendar.set(Calendar.YEAR, 2012);
    calendar.set(Calendar.HOUR, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MONTH, 3);
    Date start = calendar.getTime();

    // 15-06-2012
    calendar.set(Calendar.MONTH, 5);
    Date end = calendar.getTime();

    calendar.setTime(start);//from  ww w . j  a  v a2  s  . c om
    Date d = null;
    while ((d = calendar.getTime()).before(end) || d.equals(end)) {
        int day = calendar.get(Calendar.DAY_OF_WEEK);
        if (day != Calendar.SATURDAY && day != Calendar.SUNDAY) {
            System.out.println(d);
        }
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Calendar cal = new GregorianCalendar();

    // Get the components of the time
    int hour12 = cal.get(Calendar.HOUR); // 0..11
    int hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23
    int min = cal.get(Calendar.MINUTE); // 0..59
    int sec = cal.get(Calendar.SECOND); // 0..59
    int ms = cal.get(Calendar.MILLISECOND); // 0..999
    int ampm = cal.get(Calendar.AM_PM); // 0=AM, 1=PM
}

From source file:Main.java

public static void main(String args[]) {
    String months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

    Calendar calendar = Calendar.getInstance();

    // Set the time and date information and display it.
    calendar.set(Calendar.HOUR, 10);
    calendar.set(Calendar.MINUTE, 29);
    calendar.set(Calendar.SECOND, 22);

    System.out.print("Updated time: ");
    System.out.print(calendar.get(Calendar.HOUR) + ":");
    System.out.print(calendar.get(Calendar.MINUTE) + ":");
    System.out.println(calendar.get(Calendar.SECOND));
}

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    System.out.println("Current Date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-"
            + now.get(Calendar.YEAR));
    System.out.println("Current time : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":"
            + now.get(Calendar.SECOND));

    System.out.println("New date after adding 10 hours : " + (now.get(Calendar.MONTH) + 1) + "-"
            + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR));
}

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    System.out.println("Current Date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-"
            + now.get(Calendar.YEAR));
    System.out.println("Current time : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":"
            + now.get(Calendar.SECOND));

    now.add(Calendar.HOUR, 10);/*from   w w  w  .  j  a  va 2s.c  o  m*/
    System.out.println("New time after adding 10 hours : " + now.get(Calendar.HOUR_OF_DAY) + ":"
            + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND));
}

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    System.out.println("Current Date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-"
            + now.get(Calendar.YEAR));
    System.out.println("Current time : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":"
            + now.get(Calendar.SECOND));

    now = Calendar.getInstance();
    now.add(Calendar.HOUR, -3);// ww w .j ava2 s. com
    System.out.println("Time before 3 hours : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE)
            + ":" + now.get(Calendar.SECOND));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    // Get the current time in Hong Kong
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("Hongkong"));

    int hour12 = cal.get(Calendar.HOUR); // 0..11
    int minutes = cal.get(Calendar.MINUTE); // 0..59
    int seconds = cal.get(Calendar.SECOND); // 0..59
    boolean am = cal.get(Calendar.AM_PM) == Calendar.AM;

    // Get the current hour-of-day at GMT
    cal.setTimeZone(TimeZone.getTimeZone("GMT"));
    int hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23

    // Get the current local hour-of-day
    cal.setTimeZone(TimeZone.getDefault());
    hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23
}