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 calculateNextAlarmTime(int repetition) {
    if (repetition == 0)
        return null;
    Calendar alarmTime = Calendar.getInstance();
    alarmTime.set(Calendar.HOUR_OF_DAY, 20);
    alarmTime.set(Calendar.MINUTE, 0);
    alarmTime.set(Calendar.SECOND, 0);

    int day_of_week = alarmTime.get(Calendar.DAY_OF_WEEK) - 2;
    if (day_of_week == -1)
        day_of_week = 6;// sunday
    repetition &= 0x7f;/*from  w  w  w.j  a v a2 s  .  com*/
    int rot = (repetition >> (day_of_week + 1)) | (repetition << (7 - day_of_week - 1));
    rot &= 0x7f;
    int ndays = 0;
    for (ndays = 0; ndays < 7; ndays++) {
        if ((rot & (1 << ndays)) != 0)
            break;
    }
    alarmTime.add(Calendar.DATE, ndays + 1);

    return alarmTime;
}

From source file:Main.java

public static String getMsgTime(long msg_time) {
    Calendar cl = Calendar.getInstance();
    cl.setTimeInMillis(msg_time); //here your time in miliseconds
    String hour = String.format("%02d", cl.get(Calendar.HOUR_OF_DAY));
    String min = String.format("%02d", cl.get(Calendar.MINUTE));
    String sec = String.format("%02d", cl.get(Calendar.SECOND));
    String time = hour + ":" + min;
    return time;//from   w  ww.j av  a 2 s  .  co  m
}

From source file:Main.java

@NonNull
public static String getTime() {
    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);
}

From source file:Main.java

public static Date endOfThisMonth() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
    calendar.set(Calendar.HOUR, calendar.getActualMaximum(Calendar.HOUR));
    calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
    calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
    calendar.set(Calendar.MILLISECOND, calendar.getActualMaximum(Calendar.MILLISECOND));

    return calendar.getTime();
}

From source file:Main.java

public static Date beginOfThisMonth() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
    calendar.set(Calendar.HOUR, calendar.getActualMinimum(Calendar.HOUR));
    calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
    calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND));
    calendar.set(Calendar.MILLISECOND, calendar.getActualMinimum(Calendar.MILLISECOND));

    return calendar.getTime();
}

From source file:Main.java

public static Date dayBegin(final Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);//  ww w .  j av a 2 s .  co  m
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c.getTime();
}

From source file:Main.java

public static String toYYYYMMDDHHMMSS(Calendar source) {
    if (source == null) {
        return "Can't toYYYYMMDDHHMMSS source null";
    }/*from   www.  j  ava  2 s  .c  o m*/
    int YYYY = source.get(Calendar.YEAR);
    int MM = source.get(Calendar.MONTH);
    int DD = source.get(Calendar.DAY_OF_MONTH);
    int HH = source.get(Calendar.HOUR_OF_DAY);
    int mm = source.get(Calendar.MINUTE);
    int SS = source.get(Calendar.SECOND);

    return YYYY + "-" + MM + "-" + DD + " " + HH + ":" + mm + ":" + SS;
}

From source file:Main.java

/**
 * Get the SunSet for the given date//  w  ww. j ava 2s  .c o  m
 * @param date - input date
 * @return - Date with time specifying the Sun Set
 */
public static Date getSunSet(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.HOUR_OF_DAY, 18);
    cal.set(Calendar.MINUTE, 00);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Date ret = cal.getTime();
    return ret;
}

From source file:Main.java

public static String getDateString(long millitm) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(millitm);// www  . j  a  v a2 s.  c o  m
    return (setZeroPad(cal.get(Calendar.YEAR)) + "/" + setZeroPad(cal.get(Calendar.MONTH)) + "/"
            + setZeroPad(cal.get(Calendar.DATE)) + " " + setZeroPad(cal.get(Calendar.HOUR_OF_DAY)) + ":"
            + setZeroPad(cal.get(Calendar.MINUTE)) + ":" + setZeroPad(cal.get(Calendar.SECOND)));
}

From source file:Main.java

/**
 * getDateEnd//from   www  .  j av  a2s  . c o m
 * @param date the date that needs to be converted to an end date
 * @return a date at 11:59 PM
 */
public static Date getDateEnd(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 59);
    long time = cal.getTimeInMillis();
    date.setTime(time);
    return date;
}