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 String getCurrentTimeStampYYYY_MM_DD_HH_MM_SS() {
    Calendar cal = new GregorianCalendar();
    return makeTimeString(cal.get(Calendar.YEAR), 4) + "/" + makeTimeString(cal.get(Calendar.MONTH) + 1, 2)
            + "/" + makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + " "
            + 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 Date dayEnd(final Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);//from  w  ww  .ja va 2s .  co  m
    c.set(Calendar.HOUR_OF_DAY, 23);
    c.set(Calendar.MINUTE, 59);
    c.set(Calendar.SECOND, 59);
    c.set(Calendar.MILLISECOND, 999);
    return c.getTime();
}

From source file:Main.java

public static String getTimeStamp(long l) {
    Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(l);//from ww  w .java  2  s.  co m
    return makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + "."
            + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + "." + makeTimeString(cal.get(Calendar.YEAR), 4)
            + " " + 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

/**
 * yyyy-MM-dd HH:mm:ss//  w w  w . j a va  2s.  co m
 */
public static String getFormatTime1(Calendar c) {
    if (null == c) {
        return "null";
    }
    DecimalFormat df = new DecimalFormat("00");
    String strCurrTime = 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 strCurrTime;
}

From source file:Main.java

public static int[] splitDate(Calendar calendar) {
    return new int[] { calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
            calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY),
            calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND) };
}

From source file:Main.java

private static boolean workingHours(Calendar calendar) {
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    int minute = calendar.get(Calendar.MINUTE);
    if (hour < 8 || hour > 17) {
        return false;
    }/*  w ww .  j  a  va 2s  .  c om*/
    if (hour == 17 && minute > 50) {
        return false;
    }
    return true;
}

From source file:Main.java

public static int getStudyDay(Context context) {
    String startStr = getSP(context, SP_LOGIN).getString(SP_KEY_LOGIN_STUDY_STARTTIME, "");
    if (!startStr.equals("")) {
        long start = Long.parseLong(startStr);
        long current = Calendar.getInstance().getTimeInMillis();

        Calendar s = Calendar.getInstance();
        s.setTimeInMillis(start);/*from www  .j a va  2s.co  m*/
        s.set(Calendar.HOUR_OF_DAY, 3);
        s.set(Calendar.MINUTE, 0);
        s.set(Calendar.SECOND, 0);
        s.set(Calendar.MILLISECOND, 0);

        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(current);
        //         c.set(Calendar.HOUR_OF_DAY, 12);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);

        start = s.getTimeInMillis();
        current = c.getTimeInMillis();

        return (int) ((current - start) / (24 * 60 * 60 * 1000));
    } else {
        return -1;
    }
}

From source file:Main.java

public static int compareDate(Calendar time1, Calendar time2) {
    int result = -1;
    if (time1.getTimeInMillis() == time2.getTimeInMillis()) {
        result = 0;/*from w  w w .j  a v  a2 s.c o  m*/
    } else if (time1.get(Calendar.YEAR) == time2.get(Calendar.YEAR)) {
        result = 6;
        if (time1.get(Calendar.MONTH) == time2.get(Calendar.MONDAY)) {
            result = 5;
            if (time1.get(Calendar.DAY_OF_MONTH) == time2.get(Calendar.DAY_OF_MONTH)) {
                result = 4;
                if (time1.get(Calendar.HOUR_OF_DAY) == time2.get(Calendar.HOUR_OF_DAY)) {
                    result = 3;
                    if (time1.get(Calendar.MINUTE) == time2.get(Calendar.MINUTE)) {
                        result = 2;
                        if (time1.get(Calendar.SECOND) == time2.get(Calendar.SECOND)) {
                            result = 1;
                        }
                    }
                }
            }
        }
    } else if (time1.get(Calendar.YEAR) / 100 == time2.get(Calendar.YEAR) / 100) {
        result = 7;
    }
    return result;
}

From source file:Main.java

public static String formatDateDiff(Calendar fromDate, Calendar toDate) {
    boolean future = false;
    if (toDate.equals(fromDate)) {
        return ("now");
    }/*from ww w  .  j a v  a 2s  .com*/
    if (toDate.after(fromDate)) {
        future = true;
    }
    StringBuilder sb = new StringBuilder();
    int[] types = new int[] { Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, Calendar.HOUR_OF_DAY,
            Calendar.MINUTE, Calendar.SECOND };
    String[] names = new String[] { ("year"), ("years"), ("month"), ("months"), ("day"), ("days"), ("hour"),
            ("hours"), ("minute"), ("minutes"), ("second"), ("seconds") };
    int accuracy = 0;
    for (int i = 0; i < types.length; i++) {
        if (accuracy > 2) {
            break;
        }
        int diff = dateDiff(types[i], fromDate, toDate, future);
        if (diff > 0) {
            accuracy++;
            sb.append(" ").append(diff).append(" ").append(names[i * 2 + (diff > 1 ? 1 : 0)]);
        }
    }
    if (sb.length() == 0) {
        return "now";
    }
    return sb.toString().trim();
}

From source file:Main.java

/**
 * Determines if the current time is between fromMillis and toMillis
 * Does so by calculating an inverse time range based on the minutes
 *
 * @param currentMillis current time in milliseconds
 * @param fromMillis    start time in milliseconds
 * @param toMillis      end time in milliseconds
 * @return whether or not the currentMillis is between fromMillis and toMillis
 *///from   ww  w.  j  a  v  a  2 s.c o m
static boolean isTimeInRange(long currentMillis, long fromMillis, long toMillis) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentMillis);

    final int currentMinuteOfDay = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE);
    calendar.setTimeInMillis(fromMillis);

    final int fromMinuteOfDay = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE);
    calendar.setTimeInMillis(toMillis);

    final int toMinuteOfDay = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE);

    if (fromMinuteOfDay <= toMinuteOfDay) {
        return (currentMinuteOfDay >= fromMinuteOfDay && currentMinuteOfDay < toMinuteOfDay);
    } else {
        return (currentMinuteOfDay >= fromMinuteOfDay || currentMinuteOfDay < toMinuteOfDay);
    }
}