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:com.ar.dev.tierra.api.dao.impl.MetodoPagoFacturaDAOImpl.java

@Override
public List<MetodoPagoFactura> getDay() {
    Criteria criteria = getSession().createCriteria(MetodoPagoFactura.class);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    Date fromDate = calendar.getTime();
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    Date toDate = calendar.getTime();
    criteria.add(Restrictions.between("fechaCreacion", fromDate, toDate));
    criteria.addOrder(Order.asc("idMetodoPagoFactura"));
    List<MetodoPagoFactura> list = criteria.list();
    return list;//from  w w w .j  a  v  a  2 s .co  m
}

From source file:com.ar.dev.tierra.api.dao.impl.DetalleFacturaDAOImpl.java

@Override
public List<DetalleFactura> getDay() {
    Criteria criteria = getSession().createCriteria(DetalleFactura.class);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    Date fromDate = calendar.getTime();
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    Date toDate = calendar.getTime();
    criteria.add(Restrictions.between("fechaCreacion", fromDate, toDate));
    criteria.addOrder(Order.asc("idDetalleFactura"));
    List<DetalleFactura> list = criteria.list();
    return list;//ww  w.j av a  2 s . c  o m
}

From source file:ru.org.linux.auth.BanIPController.java

@RequestMapping(value = "/banip.jsp", method = RequestMethod.POST)
public ModelAndView banIP(HttpServletRequest request, @RequestParam("ip") String ip,
        @RequestParam("reason") String reason, @RequestParam("time") String time,
        @RequestParam(value = "allow_posting", required = false, defaultValue = "false") boolean allowPosting,
        @RequestParam(value = "captcha_required", required = false, defaultValue = "false") boolean captchaRequired)
        throws Exception {
    Template tmpl = Template.getTemplate(request);

    if (!tmpl.isModeratorSession()) {
        throw new IllegalAccessException("Not authorized");
    }// w ww  .  ja  v  a 2 s .c om

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());

    if ("hour".equals(time)) {
        calendar.add(Calendar.HOUR_OF_DAY, 1);
    } else if ("day".equals(time)) {
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    } else if ("month".equals(time)) {
        calendar.add(Calendar.MONTH, 1);
    } else if ("3month".equals(time)) {
        calendar.add(Calendar.MONTH, 3);
    } else if ("6month".equals(time)) {
        calendar.add(Calendar.MONTH, 6);
    } else if ("remove".equals(time)) {
    } else if ("custom".equals(time)) {
        int days = ServletRequestUtils.getRequiredIntParameter(request, "ban_days");

        if (days <= 0 || days > 180) {
            throw new UserErrorException("Invalid days count");
        }

        calendar.add(Calendar.DAY_OF_MONTH, days);
    }

    Timestamp ts;
    if ("unlim".equals(time)) {
        ts = null;
    } else {
        ts = new Timestamp(calendar.getTimeInMillis());
    }

    User user = tmpl.getCurrentUser();

    user.checkCommit();

    ipBlockDao.blockIP(ip, user, reason, ts, allowPosting, captchaRequired);

    return new ModelAndView(new RedirectView("sameip.jsp?ip=" + URLEncoder.encode(ip, "UTF-8")));
}

From source file:de.uzk.hki.da.cb.PostRetrievalActionTest.java

/**
 * Post retrieval.//from   w w w  .j  a va 2s  . co  m
 */
@Test
public void testPostRetrievalDeletionAfterSomeTime() {
    Calendar now = Calendar.getInstance();
    now.add(Calendar.HOUR_OF_DAY, -49);
    j.setCreatedAt(now.getTime());

    assertTrue(Path
            .makeFile(userAreaRootPath, TEST_USER_SHORT_NAME, OUTGOING, o.getIdentifier() + FILE_EXTENSION_TAR)
            .exists());
    assertTrue(action.implementation());
    assertFalse(Path
            .makeFile(userAreaRootPath, TEST_USER_SHORT_NAME, OUTGOING, o.getIdentifier() + FILE_EXTENSION_TAR)
            .exists());
    assertTrue(o.getObject_state() == Object.ObjectStatus.ArchivedAndValidAndNotInWorkflow);

}

From source file:com.sammyun.controller.console.StaticController.java

/**
 * ???/*from  w ww .  j  av  a  2  s.  com*/
 */
@RequestMapping(value = "/build", method = RequestMethod.POST)
public @ResponseBody Map<String, Object> build(BuildType buildType, Long articleCategoryId,
        Long productCategoryId, Date beginDate, Date endDate, Integer first, Integer count, String lang,
        HttpServletRequest request, HttpServletResponse response) {
    long startTime = System.currentTimeMillis();
    if (beginDate != null) {
        Calendar calendar = DateUtils.toCalendar(beginDate);
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND));
        beginDate = calendar.getTime();
    }
    if (endDate != null) {
        Calendar calendar = DateUtils.toCalendar(endDate);
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
        endDate = calendar.getTime();
    }
    if (first == null || first < 0) {
        first = 0;
    }
    if (count == null || count <= 0) {
        count = 50;
    }
    int buildCount = 0;
    boolean isCompleted = true;
    if (lang == null) {
        lang = "zh_CN";
    }
    staticService.setLocale(lang);
    WebUtils.removeCookie(request, response, langCookieName);
    WebUtils.addCookie(request, response, langCookieName, lang);
    if (buildType == BuildType.index) {
        buildCount = staticService.buildIndex();
    } else if (buildType == BuildType.article) {
    } else if (buildType == BuildType.other) {
        buildCount = staticService.buildOther();
    }
    long endTime = System.currentTimeMillis();
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("first", first);
    map.put("buildCount", buildCount);
    map.put("buildTime", endTime - startTime);
    map.put("isCompleted", isCompleted);
    return map;
}

From source file:net.seratch.taskun.util.CalendarUtil.java

 public static Calendar getCalendar(int yyyy, int mm, int dd, int hh,
      int mi, int ss) {
   Calendar cal = getCalendar(yyyy, mm, dd);
   cal.set(Calendar.HOUR_OF_DAY, hh);
   cal.set(Calendar.MINUTE, mi);//from   w  ww  .  j a  v a  2  s  .c o  m
   cal.set(Calendar.SECOND, ss);
   return cal;
}

From source file:org.sharetask.service.StatisticsServiceImpl.java

private StatisticsDataDTO getStatisticsPerLastHour() {
    Calendar calendar = Calendar.getInstance();
    Date date = DateUtils.truncate(calendar.getTime(), Calendar.HOUR_OF_DAY);
    return new StatisticsDataDTO.Builder().usersCount(userInformationRepository.getCountCreatedAfter(date))
            .workspacesCount(workspaceRepository.getCountCreatedAfter(date))
            .tasksCount(taskRepository.getCountCreatedAfter(date)).build();
}

From source file:net.sf.l2j.gameserver.model.entity.ClanHallSiege.java

public void setNewSiegeDate(long siegeDate, int ClanHallId, int hour) {
    Calendar tmpDate = Calendar.getInstance();
    if (siegeDate <= System.currentTimeMillis()) {
        tmpDate.setTimeInMillis(System.currentTimeMillis());
        tmpDate.add(Calendar.DAY_OF_MONTH, 3);
        tmpDate.set(Calendar.DAY_OF_WEEK, 6);
        tmpDate.set(Calendar.HOUR_OF_DAY, hour);
        tmpDate.set(Calendar.MINUTE, 0);
        tmpDate.set(Calendar.SECOND, 0);
        setSiegeDate(tmpDate);//  w w w .j  a  v  a  2s .c o  m
        Connection con = null;
        try {
            con = L2DatabaseFactory.getInstance().getConnection();
            PreparedStatement statement = con
                    .prepareStatement("UPDATE clanhall_siege SET siege_data=? WHERE id = ?");
            statement.setLong(1, getSiegeDate().getTimeInMillis());
            statement.setInt(2, ClanHallId);
            statement.execute();
            statement.close();
        } catch (Exception e) {
            _log.error("Exception: can't save clanhall siege date: " + e.getMessage(), e);
        } finally {
            try {
                if (con != null)
                    con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:Main.java

/**
 *
 * This method is a utility method to create a new java.sql.Date in one line.
 *
 * @param year//from  w w w .j  a v a 2  s  .co m
 * @param month
 * @param day
 * @param hour
 * @param minute
 * @param second
 *
 * @return a populated java.sql.Date with the year, month, hour, minute, and second populated, with no value for millisecond.
 *
 */
public static java.sql.Date newDate(Integer year, Integer month, Integer day, Integer hour, Integer minute,
        Integer second) {

    // test for null arguments
    if (year == null) {
        throw new IllegalArgumentException("Argument 'year' passed in was null.");
    }
    if (month == null) {
        throw new IllegalArgumentException("Argument 'month' passed in was null.");
    }
    if (day == null) {
        throw new IllegalArgumentException("Argument 'day' passed in was null.");
    }
    if (hour == null) {
        throw new IllegalArgumentException("Argument 'hour' passed in was null.");
    }
    if (minute == null) {
        throw new IllegalArgumentException("Argument 'minute' passed in was null.");
    }
    if (second == null) {
        throw new IllegalArgumentException("Argument 'second' passed in was null.");
    }

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month);
    calendar.set(Calendar.DAY_OF_MONTH, day);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, second);
    calendar.clear(Calendar.MILLISECOND);

    return new java.sql.Date(calendar.getTimeInMillis());
}

From source file:com.lohika.alp.reporter.fe.dao.TestMethodDAOImpl.java

private DetachedCriteria getFilteredCriteria(TestMethodFilter filter) {
    DetachedCriteria criteria = DetachedCriteria.forClass(TestMethod.class);

    criteria.createAlias("testInstance", "testInstance").createAlias("testInstance.testClass", "testClass")
            .createAlias("testInstance.test", "test");

    if (filter.getFrom() != null && filter.getTill() != null) {
        Calendar c = Calendar.getInstance();

        c.setTime(filter.getFrom());/*  www.  ja  v a  2  s. c o m*/
        c.set(Calendar.HOUR_OF_DAY, c.getActualMinimum(Calendar.HOUR_OF_DAY));
        c.set(Calendar.MINUTE, c.getActualMinimum(Calendar.MINUTE));
        c.set(Calendar.SECOND, c.getActualMinimum(Calendar.SECOND));
        c.set(Calendar.MILLISECOND, c.getActualMinimum(Calendar.MILLISECOND));
        Date from = c.getTime();

        c.setTime(filter.getTill());
        c.set(Calendar.HOUR_OF_DAY, c.getActualMaximum(Calendar.HOUR_OF_DAY));
        c.set(Calendar.MINUTE, c.getActualMaximum(Calendar.MINUTE));
        c.set(Calendar.SECOND, c.getActualMaximum(Calendar.SECOND));
        c.set(Calendar.MILLISECOND, c.getActualMaximum(Calendar.MILLISECOND));
        Date till = c.getTime();

        criteria.add(Restrictions.between("startDate", from.getTime(), till.getTime()));
    }

    if (filter.getCl() != "" && filter.getCl() != null) {
        try {
            criteria.add(querytr.translate("testClass.name", filter.getCl()));
        } catch (QueryTranslatorException e) {
            // TODO Put QueryTranslatorException into log
            e.printStackTrace();
        }
    }

    if (filter.getGr() != "" && filter.getGr() != null) {
        criteria.createAlias("groups", "groups");

        try {
            criteria.add(querytr.translate("groups.name", filter.getGr()));
        } catch (QueryTranslatorException e) {
            // TODO Put QueryTranslatorException into log
            e.printStackTrace();
        }
    }

    return criteria;
}