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 setDateTime(Date originalDate, int hour, int minute, int second) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(originalDate);/*from  w  ww . ja va2  s. c o  m*/
    cal.set(Calendar.HOUR, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:Main.java

public static boolean isDateAfterToday(Calendar calendar) {
    Calendar validationCalendar = Calendar.getInstance();
    validationCalendar.setTime(calendar.getTime());
    validationCalendar.set(Calendar.MILLISECOND, todayCalendar.get(Calendar.MILLISECOND));
    validationCalendar.set(Calendar.SECOND, todayCalendar.get(Calendar.SECOND));
    validationCalendar.set(Calendar.MINUTE, todayCalendar.get(Calendar.MINUTE));
    validationCalendar.set(Calendar.HOUR_OF_DAY, todayCalendar.get(Calendar.HOUR_OF_DAY));
    return validationCalendar.getTime().after(todayCalendar.getTime());
}

From source file:Main.java

public static boolean isDateBeforeToday(Calendar calendar) {
    Calendar validationCalendar = Calendar.getInstance();
    validationCalendar.setTime(calendar.getTime());
    validationCalendar.set(Calendar.MILLISECOND, todayCalendar.get(Calendar.MILLISECOND));
    validationCalendar.set(Calendar.SECOND, todayCalendar.get(Calendar.SECOND));
    validationCalendar.set(Calendar.MINUTE, todayCalendar.get(Calendar.MINUTE));
    validationCalendar.set(Calendar.HOUR_OF_DAY, todayCalendar.get(Calendar.HOUR_OF_DAY));
    return validationCalendar.getTime().before(todayCalendar.getTime());
}

From source file:Main.java

/**
 * Converts input time from Java to DOS format
 * @param time/*from   ww  w  .  j a v  a  2  s . c o m*/
 * @return time in DOS format 
 */
public static long javaToDosTime(long time) {

    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(time);

    int year = cal.get(Calendar.YEAR);
    if (year < 1980) {
        return (1 << 21) | (1 << 16);
    }
    return (year - 1980) << 25 | (cal.get(Calendar.MONTH) + 1) << 21 | cal.get(Calendar.DATE) << 16
            | cal.get(Calendar.HOUR_OF_DAY) << 11 | cal.get(Calendar.MINUTE) << 5
            | cal.get(Calendar.SECOND) >> 1;
}

From source file:edu.zipcloud.core.util.DateUtil.java

public static Date getEndOfDay(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//from   w  w w.ja  va 2  s  .c  om
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    calendar.set(Calendar.MILLISECOND, 999);
    return calendar.getTime();
}

From source file:Main.java

/**
 * Encode a java date/time into a 16-bit encoded DOS time
 * //from w ww  .j  a va2  s .  c o m
 * @param javaDateTime
 * @return long
 */
public static int encodeTime(long javaDateTime) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(javaDateTime);
    return 2048 * cal.get(Calendar.HOUR_OF_DAY) + 32 * cal.get(Calendar.MINUTE) + cal.get(Calendar.SECOND) / 2;
}

From source file:Main.java

public static int[] getTimeFields(long time) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(time);//  w w  w.jav  a  2s.  c  om
    int[] timeFields = new int[6];
    timeFields[0] = calendar.get(Calendar.YEAR);
    timeFields[1] = calendar.get(Calendar.MONTH);
    timeFields[2] = calendar.get(Calendar.DAY_OF_MONTH);
    timeFields[3] = calendar.get(Calendar.HOUR_OF_DAY);
    timeFields[4] = calendar.get(Calendar.MINUTE);
    timeFields[5] = calendar.get(Calendar.SECOND);
    return timeFields;
}

From source file:Main.java

/**
 * Creates a calendar object with the next absolute time determined by hour and minute
 * @param hourOfDay//from w  w w . j  av a2s  . c o  m
 * @param minute
 * @return
 */
public static Calendar getNextAlarmTimeAbsolute(int hourOfDay, int minute) {
    Calendar cal = Calendar.getInstance();
    Calendar calNow = (Calendar) cal.clone();

    cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    if (cal.compareTo(calNow) <= 0) {
        //Today's time passed, count to tomorrow
        cal.add(Calendar.DATE, 1);
    }
    return cal;
}

From source file:Main.java

/**
 * Packs java time value into an MS-DOS time value.
 * @param time the time value/*  w w  w.  j a  v a 2 s .com*/
 * @return the MS-DOS packed time
 */
public static int packTime(long time) {
    Calendar c = Calendar.getInstance();
    c.setTime(new Date(time));

    int seconds = c.get(Calendar.SECOND);
    int minutes = c.get(Calendar.MINUTE);
    int hours = c.get(Calendar.HOUR_OF_DAY);

    /*
     * Here is how MS-DOS packs a time value:
     * 0-4: seconds (divided by 2 because we only have 5 bits = 32 different numbers)
     * 5-10: minutes (6 bits = 64 possible values)
     * 11-15: hours (5 bits = 32 possible values)
     *
     * source: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724247(v=vs.85).aspx
     */
    return (hours << 11) | (minutes << 5) | (seconds / 2);
}

From source file:Main.java

/**
 * This method returns a new Date with a specified hour, minute, second and millis
 *
 * @param date/*from www .ja v  a 2 s  . c o m*/
 *         Start date
 * @param hourOfDay
 *         Target hour (0 - 23)
 * @param minute
 *         Target minute (0 - 59)
 * @param second
 *         Target second (0 - 59)
 * @param millis
 *         Target millis (0 - 999)
 *
 * @return The requested time
 */
public static Date setTime(Date date, int hourOfDay, int minute, int second, int millis) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, millis);
    return cal.getTime();
}