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 Calendar GetThisYearLeftRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}

From source file:Main.java

public static int getGapDay(Date startDate, Date endDate) {
    Calendar fromCalendar = Calendar.getInstance();
    fromCalendar.setTime(startDate);/*from   w w w.java  2s.  com*/
    fromCalendar.set(Calendar.HOUR_OF_DAY, 0);
    fromCalendar.set(Calendar.MINUTE, 0);
    fromCalendar.set(Calendar.SECOND, 0);
    fromCalendar.set(Calendar.MILLISECOND, 0);

    Calendar toCalendar = Calendar.getInstance();
    toCalendar.setTime(endDate);
    toCalendar.set(Calendar.HOUR_OF_DAY, 0);
    toCalendar.set(Calendar.MINUTE, 0);
    toCalendar.set(Calendar.SECOND, 0);
    toCalendar.set(Calendar.MILLISECOND, 0);

    return (int) ((toCalendar.getTime().getTime() - fromCalendar.getTime().getTime()) / (1000 * 60 * 60 * 24));
}

From source file:Main.java

public static Calendar GetLastYearRightRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}

From source file:Main.java

public static String getTimeString(long millitm) {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    cal.setTimeInMillis(millitm);/* ww  w  .jav  a 2s .c o m*/
    return (setZeroPad(cal.get(Calendar.HOUR)) + ":" + setZeroPad(cal.get(Calendar.MINUTE)) + ":"
            + setZeroPad(cal.get(Calendar.SECOND)));
}

From source file:Main.java

public static int[] getCurrentTime() {
    Calendar now = Calendar.getInstance();
    now.setTimeInMillis(System.currentTimeMillis());
    int[] time = new int[3];
    time[0] = now.get(Calendar.HOUR_OF_DAY);
    time[1] = now.get(Calendar.MINUTE);
    time[2] = now.get(Calendar.SECOND);
    return time;// ww w.j a va 2s .  c  o  m
}

From source file:Main.java

static Calendar toNearestWholeHour(Calendar d) {
    Calendar c = new GregorianCalendar();
    c.setTime(d.getTime());//from w w w  .j av a  2  s  .  c  om

    if (c.get(Calendar.MINUTE) >= 30)
        c.add(Calendar.HOUR, 1);

    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);

    return c;
}

From source file:Main.java

private static Calendar prepareCalendar(int hourOfDay, int minute) {
    Calendar calNow = Calendar.getInstance();
    Calendar calSet = (Calendar) calNow.clone();

    calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
    calSet.set(Calendar.MINUTE, minute);
    calSet.set(Calendar.SECOND, 0);
    calSet.set(Calendar.MILLISECOND, 0);

    if (calSet.compareTo(calNow) <= 0) {
        // Today Set time passed, count to tomorrow
        calSet.add(Calendar.DATE, 1);
    }/* ww w  .  j a v a2  s.c  o m*/
    return calSet;
}

From source file:Main.java

public static Calendar nextMonday() {
    Calendar date = new GregorianCalendar();
    while (date.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        date.add(Calendar.DATE, 1);
    }//from  w  ww.  j  av  a  2s.c  o  m
    date.set(Calendar.HOUR_OF_DAY, 0);
    date.set(Calendar.MINUTE, 0);
    date.set(Calendar.SECOND, 0);
    date.set(Calendar.MILLISECOND, 0);
    return date;
}

From source file:Main.java

public static long intID() {
    Calendar c = Calendar.getInstance();

    int dia = c.get(Calendar.DAY_OF_MONTH);
    int ano = c.get(Calendar.YEAR) - 2010;
    int mes = c.get(Calendar.MONTH) + 1;

    int hora = c.get(Calendar.HOUR_OF_DAY);
    int minuto = c.get(Calendar.MINUTE);
    int segundo = c.get(Calendar.SECOND);
    int milisec = c.get(Calendar.MILLISECOND);

    return Long.parseLong("" + ano + mes + dia + hora + minuto + segundo + milisec);
}

From source file:Main.java

public static String getNow() {
    final Calendar calendar = Calendar.getInstance();
    return calendar.get(Calendar.YEAR) + "/" + calendar.get(Calendar.MONTH) + 1 + "/"
            + calendar.get(Calendar.DAY_OF_MONTH) + "/" + " " + calendar.get(Calendar.HOUR_OF_DAY) + ":"
            + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND);
}