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

/**
 * @param startDateTime/*from  w w  w  . java 2s .com*/
 * @param endDateTime
 * @return the difference in days between the second timestamp and first
 */
public static double getDifferenceInDays(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);
    startCompare.set(Calendar.SECOND, 0);
    startCompare.set(Calendar.MILLISECOND, 0);

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

    return (endCompare.getTimeInMillis() - startCompare.getTimeInMillis()) / (24 * 60 * 60 * 1000);
}

From source file:Utils.java

public static Date getEndOfDay(Date day, Calendar cal) {
    if (day == null)
        day = new Date();
    cal.setTime(day);//from   w ww  .  j  a  va2s .co  m
    cal.set(Calendar.HOUR_OF_DAY, cal.getMaximum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cal.getMaximum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
    return cal.getTime();
}

From source file:Main.java

/**
 * Compares (only) the time of two Calendar objects
 * @param firstTime The first calendar object
 * @param secondTime The second calendar object
 * @return -1 if the time of the first calendar object is earlier than the second calendar object,
 *          1 if the time of the second calendar object is earlier than the first calendar object,
 *          0 if the times are equal//w ww . j  av  a  2 s  .c  om
 */
public static int compareTime(Calendar firstTime, Calendar secondTime) {
    if (firstTime.get(Calendar.HOUR_OF_DAY) < secondTime.get(Calendar.HOUR_OF_DAY)) {
        return -1;
    } else if (firstTime.get(Calendar.HOUR_OF_DAY) > secondTime.get(Calendar.HOUR_OF_DAY)) {
        return 1;
    }
    if (firstTime.get(Calendar.MINUTE) < secondTime.get(Calendar.MINUTE)) {
        return -1;
    } else if (firstTime.get(Calendar.MINUTE) > secondTime.get(Calendar.MINUTE)) {
        return 1;
    }
    return 0;
}

From source file:Main.java

public static Calendar createCalendar(int hour, int minute) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, 0);
    return calendar;
}

From source file:Main.java

protected static String toString(GregorianCalendar g1) {
    StringBuilder buffer = new StringBuilder();

    buffer.append(// www .jav a 2 s . c o m
            g1.get(Calendar.YEAR) + "/" + (g1.get(Calendar.MONTH) + 1) + "/" + g1.get(Calendar.DAY_OF_MONTH));
    buffer.append("  ");
    buffer.append(g1.get(Calendar.HOUR_OF_DAY) + ":" + g1.get(Calendar.MINUTE) + ":" + g1.get(Calendar.SECOND)
            + "." + g1.get(Calendar.MILLISECOND));

    return buffer.toString();
}

From source file:com.joken.common.utils.ConverterUtils.java

/**
 * ?/*from  w ww  . j  a  v a 2  s  . c  o  m*/
 * 
 * @param time
 *            :08:30:00
 * @param separator
 *            :
 * @return 
 */
public static Long string2TimeSeconds(String time, String separator) {
    Calendar cl = Calendar.getInstance();
    String[] times = time.split(separator);
    cl.set(Calendar.HOUR_OF_DAY, Integer.valueOf(times[0]));
    cl.set(Calendar.MINUTE, Integer.valueOf(times[1]));
    cl.set(Calendar.SECOND, Integer.valueOf(times[2]));
    cl.set(Calendar.MILLISECOND, 0);
    return cl.getTimeInMillis() / 1000;
}

From source file:Main.java

public static int compare(Calendar date1, Calendar date2) {
    int i = date1.get(Calendar.YEAR);
    int j = date2.get(Calendar.YEAR);

    if (i > j)
        return 1;
    if (i < j)
        return -1;

    i = date1.get(Calendar.MONTH);
    j = date2.get(Calendar.MONTH);
    if (i > j)
        return 1;
    if (i < j)
        return -1;

    i = date1.get(Calendar.DAY_OF_MONTH);
    j = date2.get(Calendar.DAY_OF_MONTH);
    if (i > j)
        return 1;
    if (i < j)
        return -1;

    i = date1.get(Calendar.HOUR_OF_DAY);
    j = date2.get(Calendar.HOUR_OF_DAY);
    if (i > j)
        return 1;
    if (i < j)
        return -1;

    i = date1.get(Calendar.MINUTE);
    j = date2.get(Calendar.MINUTE);
    if (i > j)
        return 1;
    if (i < j)
        return -1;

    i = date1.get(Calendar.SECOND);
    j = date2.get(Calendar.SECOND);
    if (i > j)
        return 1;
    if (i < j)
        return -1;

    return 0;/*  w  w  w.j ava2 s.com*/
}

From source file:Main.java

@NonNull
static Date convertDate(int date, int time) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 1997);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, time / 60);
    calendar.set(Calendar.MINUTE, time % 60);

    calendar.add(Calendar.DATE, date);

    return calendar.getTime();
}

From source file:Main.java

public static int[] getTime(long time, String timeZone) {
    Calendar c = Calendar.getInstance();
    if (timeZone != null && timeZone.length() != 0) {
        TimeZone tz = TimeZone.getTimeZone(timeZone);
        c = Calendar.getInstance(tz);
    }/*from w  w w . j  a v a  2s  . co  m*/
    c.setTimeInMillis(time);
    int y = c.get(Calendar.YEAR);
    int m = c.get(Calendar.MONTH);
    int d = c.get(Calendar.DAY_OF_MONTH);
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    int second = c.get(Calendar.SECOND);
    return new int[] { y, m, d, hour, minute, second };
}

From source file:de.codesourcery.eve.skills.util.Misc.java

public static Calendar stripToDay(Date d) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);/* w  w w  . j a v  a2  s .  c  o m*/
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal;
}