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:com.wiiyaya.framework.common.utils.DateUtils.java

/**
 * 00:00:00//from   w ww.  j ava 2s .  c  om
 *
 * @param date 
 * @return ??
 */
public static Date setDayStart(final Date date) {
    final Calendar c = Calendar.getInstance();
    c.setLenient(false);
    c.setTime(date);
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    return c.getTime();
}

From source file:Util.java

public static byte[] packDate(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);// www .  j  a va2s  . c om
    // Byte bits: 00000000 11111111 22222222 33333333 44444444
    // Contents : 00YYYYYY YYYYYYMM MMDDDDDH HHHHMMMM MMSSSSSS
    byte[] bytes = new byte[5];
    int s = c.get(Calendar.SECOND);
    int m = c.get(Calendar.MINUTE);
    int h = c.get(Calendar.HOUR_OF_DAY);
    int d = c.get(Calendar.DATE);
    int mm = c.get(Calendar.MONTH) + 1;
    int y = c.get(Calendar.YEAR);

    bytes[4] = (byte) ((m << 6) | s);
    bytes[3] = (byte) ((m >> 2) | (h << 4));
    bytes[2] = (byte) ((h >> 4) | (d << 1) | (mm << 6));
    bytes[1] = (byte) ((mm >> 2) | (y << 2));
    bytes[0] = (byte) (y >> 6);

    return bytes;
}

From source file:Main.java

/**
 * Decode a 16-bit encoded DOS date/time into a java date/time.
 * /*from  w w w . ja  v  a  2 s  .c o m*/
 * @param dosDate
 * @param dosTime
 * @return long
 */
public static long decodeDateTime(int dosDate, int dosTime) {
    final Calendar cal = Calendar.getInstance();

    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.SECOND, (dosTime & 0x1f) * 2);
    cal.set(Calendar.MINUTE, (dosTime >> 5) & 0x3f);
    cal.set(Calendar.HOUR_OF_DAY, dosTime >> 11);

    cal.set(Calendar.DATE, dosDate & 0x1f);
    cal.set(Calendar.MONTH, ((dosDate >> 5) & 0x0f) - 1);
    cal.set(Calendar.YEAR, 1980 + (dosDate >> 9));

    return cal.getTimeInMillis();
}

From source file:Main.java

/**
 * Formats a date/time value as a string.
 * //from   www  .ja va 2 s .  c  o  m
 * @param date the date to format
 * @return the formatted date
 */
public static String formatDateTime(Calendar date) {
    StringBuilder builder = new StringBuilder(16);
    appendField(builder, date.get(Calendar.YEAR), 4);
    appendField(builder, date.get(Calendar.MONTH) + 1, 2);
    appendField(builder, date.get(Calendar.DAY_OF_MONTH), 2);
    appendField(builder, date.get(Calendar.HOUR_OF_DAY), 2);
    appendField(builder, date.get(Calendar.MINUTE), 2);
    appendField(builder, date.get(Calendar.SECOND), 2);
    return builder.toString();
}

From source file:Main.java

private static void setStartOfDayToCalendar(Calendar c) {
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
}

From source file:Main.java

public static void moveToCalendarMinute(Calendar cal, int minute) {
    assertArgumentNotMinusInteger("minute", minute);
    cal.set(Calendar.MINUTE, minute);
}

From source file:Main.java

/***
 * Fetch the estimate current time of arrival at the destination
 * @param timeZone - The timezone at the destination
 * @param distance - how far to the target
 * @param speed - how fast we are moving
 * @return String - "HH:MM" current time at the target
 *///from ww w  . ja  va  2s  .co  m
public static String calculateEta(TimeZone timeZone, double distance, double speed) {

    // If no speed, then return an empty display string
    if (0 == speed) {
        return "--:--";
    }

    // fetch the raw ETE
    Time eteRaw = fetchRawEte(distance, speed, 0, true);

    // If the eteRaw is meaningless, then return an empty display string
    if (null == eteRaw) {
        return "--:--";
    }

    // Break the hours and minutes out
    int eteHr = eteRaw.hour;
    int eteMin = eteRaw.minute;

    // Hours greater than 99 are not displayable
    if (eteHr > 99) {
        return "XX:XX";
    }

    // Get the current local time hours and minutes
    int etaHr = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
    int etaMin = Calendar.getInstance().get(Calendar.MINUTE);

    // Add in our ETE to the current time, accounting for rollovers
    etaMin += eteMin; // Add the estimated minutes enroute to "now"
    if (etaMin > 59) {
        etaMin -= 60;
        etaHr++;
    } // account for minute rollover
    etaHr += eteHr; // Now add the hours enroute
    while (etaHr > 23) {
        etaHr -= 24;
    } // account for midnight rollover

    // Format the hours and minutes
    String strHr = String.format(Locale.getDefault(), "%02d", etaHr);
    String strMn = String.format(Locale.getDefault(), "%02d", etaMin);

    // Build string of return
    return strHr + ":" + strMn;
}

From source file:Main.java

/***
 * Fetch the estimate current time of arrival at the destination
 * @param timeZone - The timezone at the destination
 * @param distance - how far to the target
 * @param speed - how fast we are moving
 * @param bearing - direction to target//from   w  w  w. jav  a2s  .  c  om
 * @param heading - direction of movement
 * @return String - "HH:MM" current time at the target
 */
public static String calculateEta(TimeZone timeZone, double distance, double speed, double bearing,
        double heading) {

    // fetch the raw ETE
    int eteRaw = fetchRawEte(distance, speed, bearing, heading);

    // If no speed, or the eteRaw is meaningless, then return an empty display string
    if (0 == speed || eteRaw == -1) {
        return "--:--";
    }

    // Break the hours and minutes out
    int eteHr = eteRaw / 100;
    int eteMin = eteRaw % 100;

    // Hours greater than 99 are not displayable
    if (eteHr > 99) {
        return "XX:XX";
    }

    // Get the current local time hours and minutes
    int etaHr = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
    int etaMin = Calendar.getInstance().get(Calendar.MINUTE);

    // Add in our ETE to the current time, accounting for rollovers
    etaMin += eteMin; // Add the estimated minutes enroute to "now"
    if (etaMin > 59) {
        etaMin -= 60;
        etaHr++;
    } // account for minute rollover
    etaHr += eteHr; // Now add the hours enroute
    while (etaHr > 23) {
        etaHr -= 24;
    } // account for midnight rollover

    // Format the hours and minutes
    String strHr = String.format(Locale.getDefault(), "%02d", etaHr);
    String strMn = String.format(Locale.getDefault(), "%02d", etaMin);

    // Build string of return
    return strHr + ":" + strMn;
}

From source file:Main.java

/**
 * @param startDateTime//from  w ww  .  jav a 2  s .c  o  m
 * @param endDateTime
 * @return the difference in hours between the second timestamp and first
 */
public static double getDifferenceInHours(Timestamp startDateTime, Timestamp endDateTime) {
    int difference = 0;

    Calendar startCalendar = Calendar.getInstance();
    startCalendar.setTime(startDateTime);

    Calendar endCalendar = Calendar.getInstance();
    endCalendar.setTime(endDateTime);

    // First, get difference in whole days
    Calendar startCompare = Calendar.getInstance();
    startCompare.setTime(startDateTime);
    startCompare.set(Calendar.HOUR_OF_DAY, 0);
    startCompare.set(Calendar.MINUTE, 0);

    Calendar endCompare = Calendar.getInstance();
    endCompare.setTime(endDateTime);
    endCompare.set(Calendar.HOUR_OF_DAY, 0);
    endCompare.set(Calendar.MINUTE, 0);

    return (endCalendar.getTimeInMillis() - startCalendar.getTimeInMillis()) / (60.0000 * 60.0000 * 1000.0000);
}

From source file:Main.java

/**
 * Returns milliseconds of the date argument dt. If the argument
 * isIncludeTime is false then the returned milliseconds does not include
 * time./*from   w  w w .jav a2s. co  m*/
 * 
 * @param dt
 * @param isIncludeTime
 * @return
 */
private static long getDate(Date dt, boolean isIncludeTime) {
    Calendar cal = GregorianCalendar.getInstance();
    cal.setTime(dt);
    if (!isIncludeTime) {
        cal.set(Calendar.HOUR, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
    }
    return cal.getTimeInMillis();
}