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

static Calendar toNextWholeHour(Calendar d) {
    Calendar c = new GregorianCalendar();
    c.setTime(d.getTime());//from  w ww. ja  v a2s  .  c o  m
    c.add(Calendar.HOUR, 1);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    return c;
}

From source file:Main.java

public static Date getFloorDate(Date d) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);/*from  w  ww  . j a  va2 s. co  m*/

    // Set time fields to zero
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    return cal.getTime();
}

From source file:Main.java

public static int compareDate(Calendar time1, Calendar time2) {
    int result = -1;
    if (time1.getTimeInMillis() == time2.getTimeInMillis()) {
        result = 0;// w w  w.j a  va 2s  .  c  o  m
    } else if (time1.get(Calendar.YEAR) == time2.get(Calendar.YEAR)) {
        result = 6;
        if (time1.get(Calendar.MONTH) == time2.get(Calendar.MONDAY)) {
            result = 5;
            if (time1.get(Calendar.DAY_OF_MONTH) == time2.get(Calendar.DAY_OF_MONTH)) {
                result = 4;
                if (time1.get(Calendar.HOUR_OF_DAY) == time2.get(Calendar.HOUR_OF_DAY)) {
                    result = 3;
                    if (time1.get(Calendar.MINUTE) == time2.get(Calendar.MINUTE)) {
                        result = 2;
                        if (time1.get(Calendar.SECOND) == time2.get(Calendar.SECOND)) {
                            result = 1;
                        }
                    }
                }
            }
        }
    } else if (time1.get(Calendar.YEAR) / 100 == time2.get(Calendar.YEAR) / 100) {
        result = 7;
    }
    return result;
}

From source file:Main.java

public static String createJcFileName() {
    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 getCeilDate(Date d) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date(d.getTime() + 1000 * 60 * 60));

    // Set time fields to zero
    cal.set(Calendar.MINUTE, 0);/*from   w  ww .  j av  a 2 s  .  c o  m*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();

}

From source file:Main.java

static void setDate(Calendar cal, int month, int date, boolean endOfDay) {
    cal.clear();/*  w ww .  j a va2  s  . c om*/
    cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DATE, date);
    if (endOfDay) {
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        cal.set(Calendar.MILLISECOND, 999);
    } else {
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
    }
}

From source file:Main.java

public static void trimTimestamp(Calendar cal) {
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);// www  . ja  v a2s .c o  m
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
}

From source file:Main.java

public static Date firstTimeOfDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(date.getTime());

    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    Date dateBegin = new Date();
    dateBegin.setTime(calendar.getTimeInMillis());
    return dateBegin;
}

From source file:Main.java

/** Converts a Macintosh-style timestamp (seconds since
 *  January 1, 1904) into a Java date.  The timestamp is
 *  treated as a time in the default localization.
 *  Depending on that localization,/*  w w w.  j  a v a  2  s .  co  m*/
 *  there may be some variation in the exact hour of the date 
 *  returned, e.g., due to daylight savings time.
 * 
 */
public static Date timestampToDate(long timestamp) {
    Calendar cal = Calendar.getInstance();
    cal.set(1904, 0, 1, 0, 0, 0);

    // If we add the seconds directly, we'll truncate the long
    // value when converting to int.  So convert to hours plus
    // residual seconds.
    int hours = (int) (timestamp / 3600);
    int seconds = (int) (timestamp - (long) hours * 3600L);
    cal.add(Calendar.HOUR_OF_DAY, hours);
    cal.add(Calendar.SECOND, seconds);
    Date dat = cal.getTime();
    return dat;
}

From source file:Main.java

public static Date truncateDate(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from  ww  w.j ava2  s  .c  o  m
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}