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 getNow() {
    final Calendar calendar = Calendar.getInstance();
    return calendar.get(Calendar.YEAR) + "/" + calendar.get(Calendar.MONTH) + 1 + "/"
            + 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

public static int getGapCount(Date startDate, Date endDate) {
    Calendar fromCalendar = Calendar.getInstance();
    fromCalendar.setTime(startDate);//from w  w w .  j  a v  a 2 s. c  om
    fromCalendar.set(Calendar.HOUR_OF_DAY, 0);
    fromCalendar.set(Calendar.MINUTE, 0);
    fromCalendar.set(Calendar.SECOND, 0);
    fromCalendar.set(Calendar.MILLISECOND, 0);

    Calendar toCalendar = Calendar.getInstance();
    toCalendar.setTime(endDate);
    toCalendar.set(Calendar.HOUR_OF_DAY, 0);
    toCalendar.set(Calendar.MINUTE, 0);
    toCalendar.set(Calendar.SECOND, 0);
    toCalendar.set(Calendar.MILLISECOND, 0);

    return (int) ((toCalendar.getTime().getTime() - fromCalendar.getTime().getTime()) / (1000 * 60 * 60 * 24));
}

From source file:Main.java

public static Calendar getMorningCal(int hour, int minute) {
    Calendar c = Calendar.getInstance();
    if (c.get(Calendar.HOUR_OF_DAY) > 3) {
        //next day
        c.set(Calendar.DAY_OF_YEAR, c.get(Calendar.DAY_OF_YEAR) + 1);
    }//from w w w . j  av  a2s  .  c  o  m
    c.set(Calendar.HOUR_OF_DAY, hour);
    c.set(Calendar.MINUTE, minute);
    c.set(Calendar.SECOND, 0);

    return c;
}

From source file:Main.java

public static String getTimeFromLong(long l) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(l);/*from w w w.j a  v a  2  s  . c  om*/

    Calendar t = Calendar.getInstance();
    t.set(Calendar.HOUR_OF_DAY, 0);
    t.set(Calendar.MINUTE, 1);
    t.set(Calendar.SECOND, 0);

    if (c.after(t)) {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMinimumIntegerDigits(2);

        return nf.format(c.get(Calendar.HOUR_OF_DAY)) + ":" + nf.format(c.get(Calendar.MINUTE));
    } else {
        return TIME_NONE;
    }
}

From source file:Main.java

public static void clearTime(Calendar cal) {
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);//  www. j a v a  2s  .  c  om
    cal.set(Calendar.MILLISECOND, 0);

}

From source file:Main.java

public static Date getDateFromYearMonthDay(int year, int month, int day) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);/*from  w w w.ja  v  a  2 s. c  om*/
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:Main.java

/**
 * Get relativy days base on today, will return negative and positive
 * values./* ww  w .  ja v a  2s  .  c o  m*/
 * 
 * @param d
 * @return
 */
public static long getRelativeDays(Date d) {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    long curMilli = c.getTimeInMillis();
    c.setTimeInMillis(d.getTime());
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    long dMilli = c.getTimeInMillis();
    return (dMilli - curMilli) / (1 * 24 * 3600 * 1000);
}

From source file:Main.java

public static Date endOfThisMonth() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
    calendar.set(Calendar.HOUR, calendar.getActualMaximum(Calendar.HOUR));
    calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
    calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
    calendar.set(Calendar.MILLISECOND, calendar.getActualMaximum(Calendar.MILLISECOND));

    return calendar.getTime();
}

From source file:Main.java

public static String getMsgTime(long msg_time) {
    Calendar cl = Calendar.getInstance();
    cl.setTimeInMillis(msg_time); //here your time in miliseconds
    String hour = String.format("%02d", cl.get(Calendar.HOUR_OF_DAY));
    String min = String.format("%02d", cl.get(Calendar.MINUTE));
    String sec = String.format("%02d", cl.get(Calendar.SECOND));
    String time = hour + ":" + min;
    return time;//w  w w.  java2  s  .c o  m
}

From source file:Main.java

public static boolean areSameHoursAndMinuts(Calendar c1, Calendar c2) {
    if (c1 == null || c2 == null) {
        return false;
    }/* www  . j  a  va2 s.c om*/
    int t1, t2;
    t1 = c1.get(Calendar.HOUR_OF_DAY);
    t2 = c2.get(Calendar.HOUR_OF_DAY);
    t1 = t1 * c1.get(Calendar.MINUTE);
    t2 = t2 * c2.get(Calendar.MINUTE);

    if (t1 == t2) {
        return true;
    }
    return false;
}