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:MyServlet.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    GregorianCalendar calendar = new GregorianCalendar();
    Date date1 = new Date();
    calendar.setTime(date1);/* w w w.ja  v  a  2s . c om*/
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    if (hour < 9 || hour > 17) {
        chain.doFilter(request, response);
    } else {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<HTML>");
        out.println("<HEAD>");
        out.println("<TITLE>");
        out.println("Get Back to Work!");
        out.println("</TITLE>");
        out.println("</HEAD>");
        out.println("<BODY>");
        out.println("<H1>Get Back to Work!</H1>");
        out.println("Sorry, that resource is not available now.");
        out.println("</BODY>");
        out.println("</HTML>");
    }
}

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 av  a  2  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;
}

From source file:Main.java

public static boolean isToday(long dateUtc) {
    final long currentTime = System.currentTimeMillis();
    final Calendar calendarBefore = Calendar.getInstance();
    calendarBefore.setTimeInMillis(currentTime);
    calendarBefore.set(Calendar.HOUR_OF_DAY, 0);
    calendarBefore.set(Calendar.MINUTE, 0);
    calendarBefore.set(Calendar.SECOND, 0);
    calendarBefore.set(Calendar.MILLISECOND, 0);

    ////from   ww w  .jav  a2 s . c om
    final Calendar calendarAfter = Calendar.getInstance();
    calendarAfter.setTimeInMillis(currentTime);
    calendarAfter.set(Calendar.HOUR_OF_DAY, 23);
    calendarAfter.set(Calendar.MINUTE, 59);
    calendarAfter.set(Calendar.SECOND, 59);
    calendarAfter.set(Calendar.MILLISECOND, 250);
    if ((dateUtc >= calendarBefore.getTimeInMillis()) && (dateUtc <= calendarAfter.getTimeInMillis())) {
        return true;
    }
    return false;
}

From source file:com.liusoft.dlog4j.util.DateUtils.java

/**
 * ?//from  w w w  .ja v a2 s .c  o m
 * @param date
 * @param time
 * @return
 */
public static Calendar mergeDateTime(Date date, Time time) {
    Calendar cal = Calendar.getInstance();
    if (date != null)
        cal.setTime(date);
    if (time != null) {
        Calendar temp = Calendar.getInstance();
        temp.setTime(time);
        cal.set(Calendar.HOUR_OF_DAY, temp.get(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE, temp.get(Calendar.MINUTE));
        cal.set(Calendar.SECOND, temp.get(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, temp.get(Calendar.MILLISECOND));
    }
    return cal;
}

From source file:Main.java

private static void setTime(Calendar date, String time) {
    try {//from w  w w . j  a  v  a 2 s. c om
        String[] arr = time.split(":");
        int hours = Integer.parseInt(arr[0]);
        int mins = Integer.parseInt(arr[1]);
        date.set(Calendar.HOUR_OF_DAY, hours);
        date.set(Calendar.MINUTE, mins);
    } catch (Exception e) {
        Log.e("Utils.java setTime",
                "The supplied times are not properly formatted. Verify that your schedule times follow the hh:mm pattern");
    }
}

From source file:edu.zipcloud.core.util.DateUtil.java

public static Date getStartOfDay(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//from  w  ww .  java 2 s  .co  m
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getTime();
}

From source file:Main.java

public static void moveToCalendarHour(Calendar cal, int hour) {
    assertArgumentNotMinusInteger("hour", hour);
    cal.set(Calendar.HOUR_OF_DAY, hour);
}

From source file:DateHelper.java

/**
 * Calculating age from a current date//from  w  w  w.j  a  v  a2 s  . co  m
 * 
 * @param current
 * @param birthdate
 * @return Age from the current (arg) date
 */
public static float getAge(final Date current, final Date birthdate) {

    if (birthdate == null) {
        return 0;
    }
    if (current == null) {
        return getAge(birthdate);
    } else {
        final Calendar calend = new GregorianCalendar();
        calend.set(Calendar.HOUR_OF_DAY, 0);
        calend.set(Calendar.MINUTE, 0);
        calend.set(Calendar.SECOND, 0);
        calend.set(Calendar.MILLISECOND, 0);

        calend.setTimeInMillis(current.getTime() - birthdate.getTime());

        float result = 0;
        result = calend.get(Calendar.YEAR) - 1970;
        result += (float) calend.get(Calendar.MONTH) / (float) 12;
        return result;
    }

}

From source file:Main.java

/**
 * Set when the last update has been performed
 * @param context/*from  ww w .j a v a 2  s . c  o m*/
 */
public static void setLastSave(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFS_FILE, Context.MODE_PRIVATE);
    Editor editor = prefs.edit();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    int current_hours = calendar.get(Calendar.HOUR_OF_DAY);
    editor.putString(KEY_LAST_SAVE, current_hours > 13 ? "PM" : "AM");
    editor.commit();
}

From source file:com.ekom.ekomerp.global.DateTimeUtils.java

public static Calendar getCalendarWithoutTime(Date date, Locale locale) {
    Calendar calendar = Calendar.getInstance(locale);
    calendar.setTime(date);/*from   ww  w .j  a v a 2s .c  om*/
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar;
}