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 int getGapCount(Date startDate, Date endDate) {
    Calendar fromCalendar = Calendar.getInstance();
    fromCalendar.setTime(startDate);/* w  ww.  j  a v  a  2 s.c o m*/
    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 getMorningCal(int hour, int minute) {
    Calendar c = Calendar.getInstance();
    if (c.get(Calendar.HOUR_OF_DAY) > 3) {
        //next day
        c.set(Calendar.DAY_OF_YEAR, c.get(Calendar.DAY_OF_YEAR) + 1);
    }/*from  www .ja  va  2s. c  o  m*/
    c.set(Calendar.HOUR_OF_DAY, hour);
    c.set(Calendar.MINUTE, minute);
    c.set(Calendar.SECOND, 0);

    return c;
}

From source file:Main.java

public static String getTimeFromLong(long l) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(l);/*from   w  w  w .j a  v a  2 s. com*/

    Calendar t = Calendar.getInstance();
    t.set(Calendar.HOUR_OF_DAY, 0);
    t.set(Calendar.MINUTE, 1);
    t.set(Calendar.SECOND, 0);

    if (c.after(t)) {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMinimumIntegerDigits(2);

        return nf.format(c.get(Calendar.HOUR_OF_DAY)) + ":" + nf.format(c.get(Calendar.MINUTE));
    } else {
        return TIME_NONE;
    }
}

From source file:Main.java

public static void clearTime(Calendar cal) {
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);//w  ww .  j  a va2  s. c o m
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

}

From source file:Main.java

/**
 * Get relativy days base on today, will return negative and positive
 * values.//w  w w  . j  a  v  a2s  .co  m
 * 
 * @param d
 * @return
 */
public static long getRelativeDays(Date d) {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    long curMilli = c.getTimeInMillis();
    c.setTimeInMillis(d.getTime());
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    long dMilli = c.getTimeInMillis();
    return (dMilli - curMilli) / (1 * 24 * 3600 * 1000);
}

From source file:Main.java

public static Date getDateFromYearMonthDay(int year, int month, int day) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);/*from  w w  w.j av a2s.  c  o  m*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:Main.java

private static Calendar clearTimes(Calendar c) {
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);/* w  w w  .  j  a  v  a  2s .c o m*/
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c;
}

From source file:Main.java

public static List<Integer> getAllDayInMonth(int month, int year) {
    List<Integer> listDate = new ArrayList<Integer>();

    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month, 1);//w  ww .  j  a  v  a2 s .c  om
    calendar.clear(Calendar.HOUR);
    calendar.clear(Calendar.MINUTE);
    calendar.clear(Calendar.SECOND);
    int totalDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

    for (int i = 1; i <= totalDays; i++) {
        listDate.add(i);
    }
    return listDate;
}

From source file:Main.java

public static String createCCPFileName() {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(System.currentTimeMillis());

    int y = c.get(Calendar.YEAR);
    int m = c.get(Calendar.MONTH);
    int d = c.get(Calendar.DAY_OF_MONTH);
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    int second = c.get(Calendar.SECOND);
    return y + "-" + m + "-" + d + "-" + hour + "-" + minute + "-" + second;
}

From source file:Main.java

public static Date getDate(int year, int month, int day) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);//from  w  w  w.  j  a  v  a  2s.c  o m
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}