Example usage for java.util Calendar HOUR_OF_DAY

List of usage examples for java.util Calendar HOUR_OF_DAY

Introduction

In this page you can find the example usage for java.util Calendar HOUR_OF_DAY.

Prototype

int HOUR_OF_DAY

To view the source code for java.util Calendar HOUR_OF_DAY.

Click Source Link

Document

Field number for get and set indicating the hour of the day.

Usage

From source file:Main.java

public static long date2long(int hour, int minute, int second) {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, 18);
    c.set(Calendar.MINUTE, 0);//from   w w  w .ja  va2s .  c  o  m
    c.set(Calendar.SECOND, 0);
    Date d = c.getTime();
    return d.getTime();
}

From source file:Main.java

public static long getTodayMills() {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(System.currentTimeMillis());
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);/*from www .ja va  2s  . co m*/
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c.getTimeInMillis();
}

From source file:Main.java

public static long getTimeInitializeMills(long mills) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(mills);/*from w  w  w.j  a  v a 2s. co  m*/
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);

    return c.getTimeInMillis();
}

From source file:Main.java

public static int getHour() {
    Calendar c = Calendar.getInstance();
    c.setTime(new Date());
    int hour = c.get(Calendar.HOUR_OF_DAY);
    return hour;/*from  w ww.j  av a 2  s. c  o  m*/
}

From source file:Main.java

public static Calendar getBeginOfDate(long time) {
    Calendar ret = Calendar.getInstance();
    ret.setTimeInMillis(time);//from   ww  w.  ja va2s .c  om
    ret.set(Calendar.HOUR_OF_DAY, 0);
    ret.set(Calendar.MINUTE, 0);
    ret.set(Calendar.SECOND, 0);
    ret.set(Calendar.MILLISECOND, 0);

    return ret;
}

From source file:Main.java

public static boolean isSameDayHour(Calendar cal1, Calendar cal2) {
    return (isSameDay(cal1, cal2) && (cal1.get(Calendar.HOUR_OF_DAY) == cal2.get(Calendar.HOUR_OF_DAY)));
}

From source file:Main.java

public static String getHour(long time) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(time);//from   w  w w.ja  v  a 2  s. c o m
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    String times = "" + hour;
    if (minute < 10) {
        times += ":0" + minute;
    } else {
        times += ":" + minute;
    }
    return times;
}

From source file:Main.java

public static String getCurrentHour() {
    Calendar calendar = Calendar.getInstance();
    int nHour = calendar.get(Calendar.HOUR_OF_DAY);
    if (nHour < 10)
        return "0" + Integer.toString(nHour);
    else// www.j  a  v a 2s  . c o m
        return Integer.toString(nHour);
}

From source file:Main.java

public static int[] formatTimeToArray(long time) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(time);//from   w w w  .j  a  v a 2  s. c o  m
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);
    return new int[] { hour, minute };
}

From source file:Main.java

public static Calendar getNotificationCalendarDate(int hour, int minute) {
    Calendar currentCalendar = Calendar.getInstance();
    currentCalendar.set(Calendar.HOUR_OF_DAY, hour);
    currentCalendar.set(Calendar.MINUTE, minute);
    return currentCalendar;

}