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 void setDateTime(long timeStamp, Calendar currentCalender, int i) {
    currentCalender.setTimeInMillis(timeStamp);
    currentCalender.set(Calendar.DATE, 1);
    currentCalender.set(Calendar.HOUR_OF_DAY, 0);
    currentCalender.set(Calendar.MINUTE, 0);
    currentCalender.set(Calendar.SECOND, 0);
    currentCalender.set(Calendar.MILLISECOND, 0);
    currentCalender.add(Calendar.DATE, i);
}

From source file:Main.java

public static Calendar getNotificationCalendarNextDate(int hour, int minute) {
    Calendar currentCalendar = Calendar.getInstance();
    currentCalendar.add(Calendar.DATE, 1);
    currentCalendar.set(Calendar.HOUR_OF_DAY, hour);
    currentCalendar.set(Calendar.MINUTE, minute);
    return currentCalendar;

}

From source file:Main.java

public static Date plusHours(Date date, int n) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from  www. j  av a 2s.  com*/
    calendar.add(Calendar.HOUR_OF_DAY, n);
    return calendar.getTime();
}

From source file:Main.java

public static Date moveToToday(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from  ww w.  j a v  a2  s . c  o m
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);

    Calendar result = Calendar.getInstance();
    result.set(Calendar.HOUR_OF_DAY, hour);
    result.set(Calendar.MINUTE, minute);
    return result.getTime();
}

From source file:Main.java

public static Date getTheEndOfDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*w ww .j  a  va 2s.c o m*/
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    calendar.set(Calendar.MILLISECOND, 999);

    return calendar.getTime();
}

From source file:Main.java

public static Date getDateEnd(Date date) {
    Calendar calendar = Calendar.getInstance();

    calendar.setTime(date);// w ww .  j a  v a  2  s.  com
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);

    return calendar.getTime();
}

From source file:Main.java

/**
 * Convert the day in calendar in the end of the day: 23:59:59.999
 * @param c Calendar to change/* www  .  j  ava2 s  .c  o  m*/
 */
public static void endOfDay(Calendar c) {

    c.set(Calendar.HOUR_OF_DAY, 23);
    c.set(Calendar.MINUTE, 59);
    c.set(Calendar.SECOND, 59);
    c.set(Calendar.MILLISECOND, 999);
}

From source file:Main.java

public static String getTimeString(Calendar calendar) {
    if (calendar == null)
        return "";
    String hourString = String.format("%1$02d", calendar.get(Calendar.HOUR_OF_DAY));
    String minuteString = String.format("%1$02d", calendar.get(Calendar.MINUTE));
    StringBuilder dateStringBuilder = new StringBuilder();
    dateStringBuilder.append(hourString).append(":");
    dateStringBuilder.append(minuteString);
    return dateStringBuilder.toString();
}

From source file:Main.java

public static int getGapDay(Date startDate, Date endDate) {
    Calendar fromCalendar = Calendar.getInstance();
    fromCalendar.setTime(startDate);/*  w w w. j av  a  2 s.c o  m*/
    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 Date getDateStart(Date date) {
    Calendar calendar = Calendar.getInstance();

    calendar.setTime(date);//from w  ww .  j  a  va 2  s  .c  o  m
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);

    return calendar.getTime();
}