Example usage for java.util Calendar MINUTE

List of usage examples for java.util Calendar MINUTE

Introduction

In this page you can find the example usage for java.util Calendar MINUTE.

Prototype

int MINUTE

To view the source code for java.util Calendar MINUTE.

Click Source Link

Document

Field number for get and set indicating the minute within the hour.

Usage

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

/** Convert a calendar date into a string as specified by http://tools.ietf.org/html/rfc822#section-5.1
 * @param date the calendar instance to convert to a string
 * @param locale the locale to use when outputting strings such as a day of the week, or month of the year.
 * @return a string in the format: "day_abbreviation, day_of_month month_abbreviation year hour:minute:second GMT"
 *//*  w w w  .j a  v a 2  s.c  om*/
// package-private - unused
static final String convertDateToStringRfc822(Calendar date, Locale locale) {
    Date a = Date.from(Instant.now());
    a.toString();
    int day = date.get(Calendar.DAY_OF_MONTH);
    int hour = date.get(Calendar.HOUR_OF_DAY);
    int minute = date.get(Calendar.MINUTE);
    int second = date.get(Calendar.SECOND);
    String str = date.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, locale) + ", "
            + (day < 10 ? "0" + day : day) + " " + date.getDisplayName(Calendar.MONTH, Calendar.SHORT, locale)
            + " " + date.get(Calendar.YEAR) + " " + (hour < 10 ? "0" + hour : hour) + ":"
            + (minute < 10 ? "0" + minute : minute) + ":" + (second < 10 ? "0" + second : second) + " GMT";
    return str;
}

From source file:Main.java

public static Date truncateDate(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*  w  w w  . j  av a  2s  . 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();
}

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 ww w.j  av  a  2s . co m
    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()) };
}

From source file:Main.java

public static long getTomorrowZeroTimeInMillis() {
    Calendar calendar = getZeroSecondCalendar();
    calendar.add(Calendar.DAY_OF_YEAR, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    return calendar.getTimeInMillis();
}

From source file:Main.java

public static void addCalendarMinute(Calendar cal, int minutes) {
    cal.add(Calendar.MINUTE, minutes);
}

From source file:Main.java

public static void zeroFromHour(Calendar calendar) {
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
}

From source file:Main.java

/**
 * Calculate the Julian Day for a given date using the following formula:
 * JD = 367 * Y - INT(7 * (Y + INT((M + 9)/12))/4) + INT(275 * M / 9)
 *      + D + 1721013.5 + UT/24/* www . ja  v a 2 s  . c o  m*/
 *
 * Note that this is only valid for the year range 1900 - 2099.
 */
public static double calculateJulianDay(Date date) {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    cal.setTime(date);

    double hour = cal.get(Calendar.HOUR_OF_DAY) + cal.get(Calendar.MINUTE) / 60.0f
            + cal.get(Calendar.SECOND) / 3600.0f;

    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH) + 1;
    int day = cal.get(Calendar.DAY_OF_MONTH);

    double jd = 367.0 * year - Math.floor(7.0 * (year + Math.floor((month + 9.0) / 12.0)) / 4.0)
            + Math.floor(275.0 * month / 9.0) + day + 1721013.5 + hour / 24.0;
    return jd;
}

From source file:Main.java

/**
 * @param time selected in TimePicker/*from ww  w.ja  v  a  2s.  c om*/
 * @return Converted to calendar
 */

public static Calendar timeToCalendar(String time) {
    Calendar calTime = Calendar.getInstance();
    calTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.split(":")[0]));
    calTime.set(Calendar.MINUTE, Integer.parseInt(time.split(":")[1]));
    return calTime;
}

From source file:Main.java

public static String date2String(Date date, boolean printTime) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);//w  w  w. j a  va  2  s  .  co m
    if (cal.get(Calendar.YEAR) > 10000) {
        return "---";
    }
    return makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + "."
            + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + "." + makeTimeString(cal.get(Calendar.YEAR), 4)
            + (printTime
                    ? " " + makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":"
                            + makeTimeString(cal.get(Calendar.MINUTE), 2) + ":"
                            + makeTimeString(cal.get(Calendar.SECOND), 2)
                    : "");
}