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 Date getDateTimeFrom(Date time, Date date) {
    Date iTime, iDate;//w w  w . j  a  v  a  2  s . co m
    Calendar calendar = Calendar.getInstance();

    if (date == null) {
        iTime = time;
        iDate = new Date();
    } else {
        iTime = time;
        iDate = date;
    }

    Calendar calendarDate = Calendar.getInstance();
    calendarDate.setTime(iDate);

    Calendar calendarTime = Calendar.getInstance();
    if (iTime != null)
        calendarTime.setTime(iTime);

    if (iTime != null) {
        calendar.set(Calendar.MINUTE, calendarTime.get(Calendar.MINUTE));
        calendar.set(Calendar.HOUR_OF_DAY, calendarTime.get(Calendar.HOUR_OF_DAY));
    } else {
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
    }

    //calendar.set(Calendar.AM_PM, calendarTime.get(Calendar.AM_PM) );

    calendar.set(Calendar.DAY_OF_MONTH, calendarDate.get(Calendar.DAY_OF_MONTH));
    calendar.set(Calendar.MONTH, calendarDate.get(Calendar.MONTH));
    calendar.set(Calendar.YEAR, calendarDate.get(Calendar.YEAR));

    Date ret = calendar.getTime();
    Log.v("!!!!!!!!!! calendar=", "" + ret);

    return ret;
}

From source file:com.mir00r.interceptor.MaintenanceInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    //return super.preHandle(request, response, handler); //To change body of generated methods, choose Tools | Templates.

    Calendar cal = Calendar.getInstance();
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    System.out.println(hour);/*ww w. jav a 2 s  . c  om*/

    if (hour >= 15 && hour <= 25) {
        response.getWriter().write("This servers is under Maintenance. "
                + "Please Try After some Time. Sorry for this Inconvenience");
        return false;
    } else {
        return true;
    }
}

From source file:com.westlinkin.android_feedback_helper.utils.MailUntils.java

private static String getFeedbackNumber() {
    Calendar calendar = Calendar.getInstance();
    return "" + calendar.get(Calendar.YEAR)
            + Utils.formatCalendarIntValue((calendar.get(Calendar.MONTH) + 1), 2)
            + Utils.formatCalendarIntValue(calendar.get(Calendar.DAY_OF_MONTH), 2) + "-"
            + Utils.formatCalendarIntValue(calendar.get(Calendar.HOUR_OF_DAY), 2)
            + Utils.formatCalendarIntValue(calendar.get(Calendar.MINUTE), 2)
            + Utils.formatCalendarIntValue(calendar.get(Calendar.SECOND), 2) + "-"
            + Utils.formatCalendarIntValue(calendar.get(Calendar.MILLISECOND), 3);
}

From source file:TimeUtil.java

public static short mowFormat(long msecs) {
    synchronized (statFmtCal) {
        statFmtCal.setTime(new Date(msecs));

        return ((short) ((statFmtCal.get(Calendar.DAY_OF_WEEK) - 1) * 1440
                + statFmtCal.get(Calendar.HOUR_OF_DAY) * 60 + statFmtCal.get(Calendar.MINUTE)));
    }//from   w w  w  .  ja  v  a  2  s  .c o  m
}

From source file:com.qpark.eip.core.spring.auth.LimitedAccessDataProvider.java

/**
 * Get a {@link Date}, where hours, minutes, seconds and milliseconds are
 * set to 0.//from w  w  w.  j  a  v  a  2 s  .c o  m
 *
 * @return the {@link Date} and the corresponding log string.
 */
private static SimpleEntry<Date, String> getRequestDate() {
    Calendar gc = new GregorianCalendar();
    gc.set(Calendar.HOUR_OF_DAY, 0);
    gc.set(Calendar.MINUTE, 0);
    gc.set(Calendar.SECOND, 0);
    gc.set(Calendar.MILLISECOND, 0);
    String hmss = String.format("%04d%02d%02d", gc.get(Calendar.YEAR), gc.get(Calendar.MONTH) + 1,
            gc.get(Calendar.DAY_OF_MONTH));
    SimpleEntry<Date, String> entry = new SimpleEntry<Date, String>(gc.getTime(), hmss);
    return entry;
}

From source file:com.jennifer.ui.util.TimeUtil.java

public static Date add(Date d, String type, int interval) {
    Calendar c = Calendar.getInstance();
    c.setTime(d);/*  w  w  w  . j a v a 2 s . co m*/

    if (Time.YEARS.equals(type)) {
        c.add(Calendar.YEAR, interval);
    } else if (Time.MONTHS.equals(type)) {
        c.add(Calendar.MONTH, interval);
    } else if (Time.DAYS.equals(type)) {
        c.add(Calendar.DATE, interval);
    } else if (Time.HOURS.equals(type)) {
        c.add(Calendar.HOUR_OF_DAY, interval);
    } else if (Time.MINUTES.equals(type)) {
        c.add(Calendar.MINUTE, interval);
    } else if (Time.SECONDS.equals(type)) {
        c.add(Calendar.SECOND, interval);
    } else if (Time.MILLISECONDS.equals(type)) {
        c.add(Calendar.MILLISECOND, interval);
    } else if (Time.WEEKS.equals(type)) {
        c.add(Calendar.DATE, interval * 7);
    }

    return c.getTime();
}

From source file:helper.lang.DateHelperTest.java

@Test
public void testAsUtcDayCalendar() {
    Calendar localTime = Calendar.getInstance(TimeZone.getTimeZone("CST"));
    Calendar cal = DateHelper.asUtcDay(localTime);
    assertEquals(0, cal.get(Calendar.MILLISECOND));
    assertEquals(0, cal.get(Calendar.MINUTE));
    assertEquals(0, cal.get(Calendar.HOUR));
    assertEquals(0, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(DateHelper.UTC_TIME_ZONE, cal.getTimeZone());
    assertEquals(TimeZone.getTimeZone("CST"), localTime.getTimeZone());
    assertEquals(localTime.get(Calendar.YEAR), cal.get(Calendar.YEAR));
    assertEquals(localTime.get(Calendar.MONTH), cal.get(Calendar.MONTH));
    assertEquals(localTime.get(Calendar.DATE), cal.get(Calendar.DATE));
}

From source file:DateUtils.java

public static String getTime() {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());

    int hours = cal.get(Calendar.HOUR_OF_DAY);
    // use 24 hour clock
    int minutes = cal.get(Calendar.MINUTE);
    int seconds = cal.get(Calendar.SECOND);
    int milli = cal.get(Calendar.MILLISECOND);

    return formatTime(hours, minutes, seconds, milli);
}

From source file:net.duckling.ddl.util.Utility.java

public static String getDateShort(Date date) {
    Calendar calToday = Calendar.getInstance();
    calToday.set(Calendar.HOUR_OF_DAY, 0);
    Calendar calYear = Calendar.getInstance();
    calYear.set(Calendar.DAY_OF_YEAR, 1);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from   ww w. j  av a2s  .  c o m*/
    if (cal.after(calToday)) {
        return (new SimpleDateFormat("HH:mm")).format(cal.getTime());
    } else if (cal.after(calYear)) {
        return (new SimpleDateFormat("MMdd")).format(cal.getTime());
    } else {
        return (new SimpleDateFormat("yyyy")).format(cal.getTime());
    }
}

From source file:Main.java

public DateSpinner(String format, Date date) {
    super(new SpinnerDateModel(date, null, null, Calendar.HOUR_OF_DAY));
    setFormat(format);/* www  .j  a  v a2s . co  m*/
    customizeSpinner();
}