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 String genererNomFichierInexistant(String directory, String extensionFichier) {
    Calendar c = Calendar.getInstance();
    File aRetourner;/*from  w w w  .  ja v  a2  s  . c om*/
    if (extensionFichier.equals("")) {
        aRetourner = new File(
                c.get(Calendar.DAY_OF_MONTH) + "_" + c.get(Calendar.MONTH) + "_" + c.get(Calendar.YEAR) + "_"
                        + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND));
    } else if (directory.equals("")) {
        aRetourner = new File(c.get(Calendar.DAY_OF_MONTH) + "_" + c.get(Calendar.MONTH) + "_"
                + c.get(Calendar.YEAR) + "_" + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":"
                + c.get(Calendar.SECOND) + "." + extensionFichier);
    } else {
        aRetourner = new File(directory + "/" + c.get(Calendar.DAY_OF_MONTH) + "_" + c.get(Calendar.MONTH) + "_"
                + c.get(Calendar.YEAR) + "_" + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":"
                + c.get(Calendar.SECOND) + "." + extensionFichier);
    }

    return aRetourner.getPath();
}

From source file:Main.java

/**
 * Returns Date object of the next day of d.
 * @return/*from  w w  w  .  ja  v a2s  .  c o  m*/
 */
public static Date getNextDay(Date d) {
    Calendar c = Calendar.getInstance();
    if (d != null)
        c.setTime(d);
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    c.add(Calendar.DAY_OF_MONTH, 1);
    return c.getTime();
}

From source file:Main.java

public static long getEndOfMonthMs(int year, int month) {
    final Calendar date = Calendar.getInstance();

    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, date.getActualMaximum(Calendar.DAY_OF_MONTH));
    date.set(Calendar.HOUR_OF_DAY, date.getActualMaximum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMaximum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMaximum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMaximum(Calendar.MILLISECOND));
    return date.getTimeInMillis();
}

From source file:Main.java

public static long getStartOfMonthMs(int year, int month) {
    final Calendar date = Calendar.getInstance();

    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, date.getActualMinimum(Calendar.DAY_OF_MONTH));
    date.set(Calendar.HOUR_OF_DAY, date.getActualMinimum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMinimum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMinimum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMinimum(Calendar.MILLISECOND));
    return date.getTimeInMillis();
}

From source file:Main.java

public static boolean isInTimeNow(int start, int end) {
    Calendar calendar = new ThreadLocal<Calendar>() {
        protected Calendar initialValue() {
            return Calendar.getInstance();
        }/*ww  w .jav a 2 s. c  o  m*/
    }.get();
    long current = System.currentTimeMillis();
    calendar.setTimeInMillis(current);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    long originToday = calendar.getTimeInMillis();
    long distance = current - originToday;
    if (start <= distance && distance <= end) {
        return true;
    }

    return false;
}

From source file:Main.java

public static String getCurrentTimeStampHHMMSS() {
    Calendar cal = new GregorianCalendar();
    return makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":" + makeTimeString(cal.get(Calendar.MINUTE), 2)
            + ":" + makeTimeString(cal.get(Calendar.SECOND), 2);
}

From source file:Main.java

public static String getCurrentTime() {
    DecimalFormat df = new DecimalFormat("00");
    Calendar c = Calendar.getInstance();
    String currentTime = c.get(Calendar.YEAR)// + "-"
            + df.format((c.get(Calendar.MONTH) + 1)) // + "-"
            + df.format(c.get(Calendar.DAY_OF_MONTH))// + "-"
            + df.format(c.get(Calendar.HOUR_OF_DAY)) // + "-"
            + df.format(c.get(Calendar.MINUTE))// + "-"
            + df.format(c.get(Calendar.SECOND));
    return currentTime;
}

From source file:MainClass.java

public static Timestamp makeTimestamp(int year, int month, int day, int hour, int minute, int second,
        int millisecond) {
    Calendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DATE, day);//from   w w w . j a  v  a  2  s. c o m
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, millisecond);

    // now convert GregorianCalendar object to Timestamp object
    return new Timestamp(cal.getTimeInMillis());
}

From source file:Main.java

/**
 * Returns current date-time in format of yyyy-MM-dd hh:mm:ss
 * //from w  w  w .  j  a  v  a  2s  .  c o  m
 * @return date time in string.
 */
public static String getCurrentTime() {
    int yyyy = Calendar.getInstance().get(Calendar.YEAR);
    int MM = Calendar.getInstance().get(Calendar.MONTH) + 1;
    int dd = Calendar.getInstance().get(Calendar.DATE);
    int hh = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
    int mm = Calendar.getInstance().get(Calendar.MINUTE);
    int ss = Calendar.getInstance().get(Calendar.SECOND);
    String curDate = String.format("%04d-%02d-%02d %02d:%02d:%02d", yyyy, MM, dd, hh, mm, ss);

    return curDate;

}

From source file:Main.java

public static Time[] getTimesFromScheduleHour(char[] hoursArray) {

    Calendar begin = Calendar.getInstance();
    Calendar end = Calendar.getInstance();

    begin.set(Calendar.SECOND, 0);
    begin.set(Calendar.MILLISECOND, 0);
    end.set(Calendar.SECOND, 0);/*from w w w  . j  av  a2 s .  c  om*/
    end.set(Calendar.MILLISECOND, 0);

    char beginChar = hoursArray[0];
    char endChar = hoursArray[hoursArray.length - 1];

    switch (beginChar) {
    case 'A':
        begin.set(Calendar.HOUR_OF_DAY, 7);
        begin.set(Calendar.MINUTE, 30);
        break;
    case 'B':
        begin.set(Calendar.HOUR_OF_DAY, 8);
        begin.set(Calendar.MINUTE, 20);
        break;
    case 'C':
        begin.set(Calendar.HOUR_OF_DAY, 9);
        begin.set(Calendar.MINUTE, 10);
        break;
    case 'D':
        begin.set(Calendar.HOUR_OF_DAY, 10);
        begin.set(Calendar.MINUTE, 10);
        break;
    case 'E':
        begin.set(Calendar.HOUR_OF_DAY, 11);
        begin.set(Calendar.MINUTE, 10);
        break;
    case 'F':
        begin.set(Calendar.HOUR_OF_DAY, 12);
        begin.set(Calendar.MINUTE, 0);
        break;
    case 'G':
        begin.set(Calendar.HOUR_OF_DAY, 13);
        begin.set(Calendar.MINUTE, 0);
        break;
    case 'H':
        begin.set(Calendar.HOUR_OF_DAY, 13);
        begin.set(Calendar.MINUTE, 50);
        break;
    case 'I':
        begin.set(Calendar.HOUR_OF_DAY, 14);
        begin.set(Calendar.MINUTE, 50);
        break;
    case 'J':
        begin.set(Calendar.HOUR_OF_DAY, 15);
        begin.set(Calendar.MINUTE, 40);
        break;
    case 'L':
        begin.set(Calendar.HOUR_OF_DAY, 16);
        begin.set(Calendar.MINUTE, 40);
        break;
    case 'M':
        begin.set(Calendar.HOUR_OF_DAY, 17);
        begin.set(Calendar.MINUTE, 30);
        break;
    case 'N':
        begin.set(Calendar.HOUR_OF_DAY, 18);
        begin.set(Calendar.MINUTE, 30);
        break;
    case 'O':
        begin.set(Calendar.HOUR_OF_DAY, 19);
        begin.set(Calendar.MINUTE, 20);
        break;
    case 'P':
        begin.set(Calendar.HOUR_OF_DAY, 20);
        begin.set(Calendar.MINUTE, 20);
        break;
    case 'Q':
        begin.set(Calendar.HOUR_OF_DAY, 21);
        begin.set(Calendar.MINUTE, 10);
        break;
    default:
        return null;
    }

    switch (endChar) {
    case 'A':
        end.set(Calendar.HOUR_OF_DAY, 8);
        end.set(Calendar.MINUTE, 20);
        break;
    case 'B':
        end.set(Calendar.HOUR_OF_DAY, 9);
        end.set(Calendar.MINUTE, 10);
        break;
    case 'C':
        end.set(Calendar.HOUR_OF_DAY, 10);
        end.set(Calendar.MINUTE, 10);
        break;
    case 'D':
        end.set(Calendar.HOUR_OF_DAY, 11);
        end.set(Calendar.MINUTE, 0);
        break;
    case 'E':
        end.set(Calendar.HOUR_OF_DAY, 12);
        end.set(Calendar.MINUTE, 0);
        break;
    case 'F':
        end.set(Calendar.HOUR_OF_DAY, 12);
        end.set(Calendar.MINUTE, 50);
        break;
    case 'G':
        end.set(Calendar.HOUR_OF_DAY, 13);
        end.set(Calendar.MINUTE, 50);
        break;
    case 'H':
        end.set(Calendar.HOUR_OF_DAY, 14);
        end.set(Calendar.MINUTE, 40);
        break;
    case 'I':
        end.set(Calendar.HOUR_OF_DAY, 15);
        end.set(Calendar.MINUTE, 40);
        break;
    case 'J':
        end.set(Calendar.HOUR_OF_DAY, 16);
        end.set(Calendar.MINUTE, 30);
        break;
    case 'L':
        end.set(Calendar.HOUR_OF_DAY, 17);
        end.set(Calendar.MINUTE, 30);
        break;
    case 'M':
        end.set(Calendar.HOUR_OF_DAY, 18);
        end.set(Calendar.MINUTE, 20);
        break;
    case 'N':
        end.set(Calendar.HOUR_OF_DAY, 19);
        end.set(Calendar.MINUTE, 20);
        break;
    case 'O':
        end.set(Calendar.HOUR_OF_DAY, 20);
        end.set(Calendar.MINUTE, 10);
        break;
    case 'P':
        end.set(Calendar.HOUR_OF_DAY, 21);
        end.set(Calendar.MINUTE, 10);
        break;
    case 'Q':
        end.set(Calendar.HOUR_OF_DAY, 22);
        end.set(Calendar.MINUTE, 0);
        break;
    default:
        return null;
    }

    return new Time[] { new Time(begin.getTimeInMillis()), new Time(end.getTimeInMillis()) };
}