Example usage for java.util Calendar DATE

List of usage examples for java.util Calendar DATE

Introduction

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

Prototype

int DATE

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

Click Source Link

Document

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

Usage

From source file:com.datatorrent.lib.bucket.AbstractTimeBasedBucketManager.java

private void recomputeNumBuckets() {
    Calendar calendar = Calendar.getInstance();
    long now = calendar.getTimeInMillis();
    calendar.add(Calendar.DATE, -daysSpan);
    startOfBucketsInMillis = calendar.getTimeInMillis();
    expiryTime = startOfBucketsInMillis;
    noOfBuckets = (int) Math.ceil((now - startOfBucketsInMillis) / (bucketSpanInMillis * 1.0));
    if (bucketStore != null) {
        bucketStore.setNoOfBuckets(noOfBuckets);
        bucketStore.setWriteEventKeysOnly(writeEventKeysOnly);
    }/*from  w  ww.  j a v  a  2 s .c  o m*/
    maxTimesPerBuckets = new Long[noOfBuckets];
}

From source file:DateUtils.java

/**
 * Get FTP date./*from  w  ww . j  a  va  2 s .  com*/
 */
public final static String getFtpDate(long millis) {
    StringBuffer sb = new StringBuffer(20);
    Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(millis);

    // year
    sb.append(cal.get(Calendar.YEAR));

    // month
    int month = cal.get(Calendar.MONTH) + 1;
    if (month < 10) {
        sb.append('0');
    }
    sb.append(month);

    // date
    int date = cal.get(Calendar.DATE);
    if (date < 10) {
        sb.append('0');
    }
    sb.append(date);

    // hour
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    if (hour < 10) {
        sb.append('0');
    }
    sb.append(hour);

    // minute
    int min = cal.get(Calendar.MINUTE);
    if (min < 10) {
        sb.append('0');
    }
    sb.append(min);

    // second
    int sec = cal.get(Calendar.SECOND);
    if (sec < 10) {
        sb.append('0');
    }
    sb.append(sec);

    // millisecond
    sb.append('.');
    int milli = cal.get(Calendar.MILLISECOND);
    if (milli < 100) {
        sb.append('0');
    }
    if (milli < 10) {
        sb.append('0');
    }
    sb.append(milli);
    return sb.toString();
}

From source file:org.lieuofs.commune.biz.GestionMutationCommuneTest.java

@Test
public void testRechercherMutationJurassienne() {
    // Recherche des mutations sur le canton du Jura
    // Lors de la cration du canton le 01.01.1979, 82 communes ont migr du canton de Berne
    // dans le canton du Jura.
    MutationCommuneCritere critere = new MutationCommuneCritere();
    critere.setCodeCanton("BE");
    Calendar cal = Calendar.getInstance();
    cal.set(1978, Calendar.DECEMBER, 31);
    critere.setDateDebut(cal.getTime());
    cal.add(Calendar.DATE, 1);
    critere.setDateFin(cal.getTime());/*from   w  ww . j a  va 2 s .co  m*/
    List<IMutationCommune> mutations = gestionnaire.rechercherMutation(critere);
    List<String> descriptions = new ArrayList<String>();
    for (IMutationCommune mut : mutations) {
        descriptions.add(mut.getDescription());
    }
    assertThat(mutations).hasSize(82);
}

From source file:DateUtils.java

public static final String getDateTimeFromDate(Date dt, String tzString) {
    try {// w  w  w  .  j a v a  2  s. co  m
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(dt);
        gc.setTimeZone(TimeZone.getTimeZone(tzString));
        StringBuffer ret = new StringBuffer();
        ret.append(gc.get(Calendar.YEAR));
        ret.append("-");
        ret.append(gc.get(Calendar.MONTH) - 1);
        ret.append("-");
        ret.append(gc.get(Calendar.DATE));
        ret.append(" ");
        ret.append(gc.get(Calendar.HOUR));
        ret.append(":");
        ret.append(gc.get(Calendar.MINUTE));
        ret.append(" ");
        if (gc.get(Calendar.AM_PM) == 0) {
            ret.append("AM");
        } else {
            ret.append("PM");
        }
        return ret.toString();
    } catch (Exception e) {
        return "";
    }
}

From source file:org.kuali.mobility.events.controllers.CalendarController.java

@RequestMapping(value = "/month", method = RequestMethod.GET)
public String month(HttpServletRequest request, Model uiModel, @RequestParam(required = false) String date) {
    User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    SimpleDateFormat my = new SimpleDateFormat("yyyyMM");
    Calendar selectedDate = Calendar.getInstance();
    try {/*from ww w  .jav a  2s. c om*/
        if (date != null) {
            selectedDate.setTime(my.parse(date));
        }
    } catch (ParseException e) {

    }
    try {
        Filter filter = (Filter) request.getSession().getAttribute("calendar.event.filterId");
        MonthViewEvents monthEvents = calendarEventOAuthService.retrieveMonthEvents(user.getUserId(),
                selectedDate.getTime(), filter != null ? filter.getFilterId() : null);
        uiModel.addAttribute("viewData", monthEvents.getViewData());
        uiModel.addAttribute("appData", monthEvents.getAppData());

        int days = selectedDate.getActualMaximum(Calendar.DATE);

        Calendar startDate = (Calendar) selectedDate.clone();
        startDate.set(Calendar.DATE, selectedDate.getActualMinimum(Calendar.DATE));
        days += startDate.get(Calendar.DAY_OF_WEEK) - 1;

        Calendar endDate = (Calendar) selectedDate.clone();
        endDate.set(Calendar.DATE, selectedDate.getActualMaximum(Calendar.DATE));
        days += 7 - endDate.get(Calendar.DAY_OF_WEEK);

        startDate.set(Calendar.DAY_OF_WEEK, 1);
        Map<String, MobileDayOfMonth> daysInMonth = new LinkedHashMap<String, MobileDayOfMonth>();

        uiModel.addAttribute("selectedDate", sdf.format(selectedDate.getTime()));
        for (int i = 0; i < days; i++) {
            MobileDayOfMonth mobileDayOfMonth = new MobileDayOfMonth(startDate.get(Calendar.DATE));
            mobileDayOfMonth.setCurrentMonth(startDate.get(Calendar.MONTH) == selectedDate.get(Calendar.MONTH));
            if (!mobileDayOfMonth.isCurrentMonth()) {
                mobileDayOfMonth.setBeforeCurrentMonth(
                        startDate.get(Calendar.MONTH) < selectedDate.get(Calendar.MONTH));
            }
            mobileDayOfMonth.setMonthYear(my.format(startDate.getTime()));
            mobileDayOfMonth.setDayOfWeek(startDate.get(Calendar.DAY_OF_WEEK));
            daysInMonth.put(sdf.format(startDate.getTime()), mobileDayOfMonth);
            startDate.add(Calendar.DATE, 1);
        }

        for (Iterator iterator = monthEvents.getEvents().entrySet().iterator(); iterator.hasNext();) {
            Map.Entry<String, List<CalendarViewEvent>> entry = (Map.Entry<String, List<CalendarViewEvent>>) iterator
                    .next();
            MobileDayOfMonth dayInMonth = daysInMonth.get(entry.getKey());
            dayInMonth.setHasEvents(true);
            dayInMonth.setEvents(entry.getValue());
        }
        uiModel.addAttribute("events", daysInMonth);

        Calendar previousCalendar = (Calendar) selectedDate.clone();
        previousCalendar.set(Calendar.DATE, 1);
        previousCalendar.getTime();
        previousCalendar.add(Calendar.MONTH, -1);

        Calendar nextCalendar = (Calendar) selectedDate.clone();
        nextCalendar.set(Calendar.DATE, 1);
        nextCalendar.getTime();
        nextCalendar.add(Calendar.MONTH, 1);

        uiModel.addAttribute("previousMonth", my.format(previousCalendar.getTime()));
        uiModel.addAttribute("nextMonth", my.format(nextCalendar.getTime()));
        uiModel.addAttribute("monthYear", my.format(selectedDate.getTime()));
        uiModel.addAttribute("today", sdf.format(new Date()));
        uiModel.addAttribute("filter", filter);
    } catch (PageLevelException pageLevelException) {
        uiModel.addAttribute("message", pageLevelException.getMessage());
        return "calendar/message";
    }
    return "calendar/month";
}

From source file:org.starfishrespect.myconsumption.server.business.stats.StatisticsUpdater.java

/**
 * Cycle through each period of a given sensor to compute its associated stats.
 *
 * @param id sensor id of the sensor/*from  w w  w.  java  2  s. c o  m*/
 * @param today today's date at midnight
 * @throws DaoException thrown if something goes wrong while communicating with the db
 */
private void computeStatsForSensor(String id, Date today) throws DaoException {
    // Find latest DayStat available in db
    // Start by getting all stats sorted for this sensor id
    List<DayStat> dayStats = mDayStatRepository.findBySensorId(id);
    Collections.sort(dayStats, new DayStatComparator());

    Date dayDb;

    // If nothing has been found, the first day will be the first value of the sensor
    if (dayStats.size() == 0) {
        dayDb = mSensorRepository.getSensor(id).getFirstValue();
    } else {
        // else the first day will be the latest day found in db
        DayStat lastDayStat = dayStats.get(dayStats.size() - 1);
        dayDb = lastDayStat.getDay();
    }

    Calendar firstDay = StatUtils.date2Calendar(StatUtils.getDateAtMidnight(dayDb));
    Calendar last = StatUtils.date2Calendar(today);
    // Compute the stat for each day starting at first day
    Calendar currentDay = StatUtils.date2Calendar(firstDay.getTime());

    while (last.compareTo(currentDay) > 0) {
        computeStatForDay(id, StatUtils.calendar2TimeStamp(currentDay));
        currentDay.add(Calendar.DATE, 1);
    }

    // if the current day in db has already been processed, return
    if (!(firstDay.getTimeInMillis() < today.getTime()))
        return;

    // Update each period
    updatePeriod(id, firstDay.getTime());

}

From source file:com.terradue.jcatalogue.client.internal.converters.AtomDateConverter.java

public Object convert(@SuppressWarnings("rawtypes") Class type, Object value) {
    if (value == null) {
        throw new ConversionException("Null values not supported in this version.");
    }/*from  w  w  w.  ja v a  2  s  .c om*/

    if (String.class == type) {
        if (value instanceof Date) {
            StringBuilder sb = new StringBuilder();
            Calendar c = getInstance(getTimeZone("GMT"));
            c.setTime((Date) value);
            sb.append(c.get(YEAR));
            sb.append('-');
            int f = c.get(MONTH);
            if (f < 9)
                sb.append('0');
            sb.append(f + 1);
            sb.append('-');
            f = c.get(DATE);
            if (f < 10)
                sb.append('0');
            sb.append(f);
            sb.append('T');
            f = c.get(HOUR_OF_DAY);
            if (f < 10)
                sb.append('0');
            sb.append(f);
            sb.append(':');
            f = c.get(MINUTE);
            if (f < 10)
                sb.append('0');
            sb.append(f);
            sb.append(':');
            f = c.get(SECOND);
            if (f < 10)
                sb.append('0');
            sb.append(f);
            sb.append('.');
            f = c.get(MILLISECOND);
            if (f < 100)
                sb.append('0');
            if (f < 10)
                sb.append('0');
            sb.append(f);
            sb.append('Z');
            return sb.toString();
        }
    } else if (Date.class == type) {
        if (value instanceof String) {
            Matcher m = PATTERN.matcher((String) value);
            if (m.find()) {
                Calendar c = Calendar.getInstance(getTimeZone("GMT"));
                int hoff = 0, moff = 0, doff = -1;
                if (m.group(9) != null) {
                    doff = m.group(9).equals("-") ? 1 : -1;
                    hoff = doff * (m.group(10) != null ? Integer.parseInt(m.group(10)) : 0);
                    moff = doff * (m.group(11) != null ? Integer.parseInt(m.group(11)) : 0);
                }
                c.set(Calendar.YEAR, Integer.parseInt(m.group(1)));
                c.set(Calendar.MONTH, m.group(2) != null ? Integer.parseInt(m.group(2)) - 1 : 0);
                c.set(Calendar.DATE, m.group(3) != null ? Integer.parseInt(m.group(3)) : 1);
                c.set(Calendar.HOUR_OF_DAY, m.group(4) != null ? Integer.parseInt(m.group(4)) + hoff : 0);
                c.set(Calendar.MINUTE, m.group(5) != null ? Integer.parseInt(m.group(5)) + moff : 0);
                c.set(Calendar.SECOND, m.group(6) != null ? Integer.parseInt(m.group(6)) : 0);
                c.set(Calendar.MILLISECOND, m.group(7) != null ? Integer.parseInt(m.group(7)) : 0);
                return c.getTime();
            }
            throw new IllegalArgumentException("Invalid Date Format");
        }
    }
    throw new ConversionException(format("type %s and value %s not supported", type, value));
}

From source file:com.greenline.guahao.web.module.home.controllers.mobile.report.MobileReportController.java

/**
 * //w  w  w.  java2 s.  c o  m
 * 
 * @param map
 * @return String
 */
@MethodRemark(value = "remark=,pageSize=,pageNo=?")
@RequestMapping(value = "/mobile/b/get/report")
public String searchMyReport(ModelMap map) {
    String mobile = request.getParameter("mobile");
    String certNo = request.getParameter("certNo");

    if (StringUtils.isBlank(mobile) || StringUtils.isBlank(certNo)) {
        Long cuserId = UserCookieUtil.getUserId(request);// ?cookieuserId
        UserDO userDO = userManager.findUserByUserId(cuserId);
        map.put("userDO", userDO);
        return "mobile/report/search_report";
    }

    if (!StringUtils.isNumeric(StringUtils.trim(mobile))) {
        map.put("hasError", true);
        map.put("message", "?????");
        UserDO userDO = new UserDO();
        userDO.setMobile(mobile);
        userDO.setCertNo(certNo);
        map.put("userDO", userDO);
        return "mobile/report/search_report";
    }

    if (!RegexUtil.isIdCard(StringUtils.trim(certNo))) {
        map.put("hasError", true);
        map.put("message", "???????");
        UserDO userDO = new UserDO();
        userDO.setMobile(mobile);
        userDO.setCertNo(certNo);
        map.put("userDO", userDO);
        return "mobile/report/search_report";
    }

    // 
    Calendar calendar = Calendar.getInstance();
    // ?
    calendar.add(Calendar.DATE, 1);
    Date end = calendar.getTime();
    // 1?
    calendar.add(Calendar.DAY_OF_MONTH, -30);
    Date start = calendar.getTime();

    // ??id
    String hospitalId = "99574b7d-e93e-4c1a-a61a-536f0b04466f";
    List<InspectionReportsDO> list = reportManager.listReport(hospitalId, StringUtils.trim(mobile),
            StringUtils.trim(certNo), start, end);
    map.put("reportList", list);

    map.put("certNO", certNo);
    map.put("mobile", mobile);

    return "mobile/report/report_list";
}

From source file:net.naijatek.myalumni.util.taglib.BirthdayListTag.java

/**
 * Process the end of this tag.//  w  ww.  ja  va  2 s  .c om
 * 
 * @throws JspException
 *             if a JSP exception has occurred
 * @return int
 */
@Override
public final int doEndTag() throws JspException {

    request = (HttpServletRequest) pageContext.getRequest();
    StringBuffer sb = new StringBuffer();
    Calendar now = new GregorianCalendar();
    String seperator = "/";
    MemberVO user = new MemberVO();
    List<MemberVO> bdays = new ArrayList<MemberVO>();
    int today = now.get(Calendar.DATE);
    String rowCss = new String();
    String rootContext = request.getContextPath();
    String rootContextName = StringUtil.trimRootContext(request.getContextPath());

    try {
        bdays = memService.getBirthdayListOfTheMonth(String.valueOf((now.get(Calendar.MONTH) + 1)));

        sb.append("<table width=\"" + this.getTableWidth()
                + "\" border=\"0\" cellspacing=\"1\" cellpadding=\"3\" align=\"center\"  class=\"tborder\">");
        sb.append("<tr>");
        sb.append("<td height=\"30\" class=\"bg0\" colspan=\"3\">Happy Birthday this month of "
                + StringUtil.convertToAlphaMonth(now.get(Calendar.MONTH) + 1)
                + " to the following Alumni's.</td>");
        sb.append("</tr>");
        sb.append("<tr  class=\"portlet-section-body\">");
        sb.append("<td height=\"30\" class=\"bg0\">Alumni Name</td>");
        sb.append("<td height=\"30\" class=\"bg0\">Departure Year</td>");
        sb.append("<td height=\"30\" class=\"bg0\">Birthday</td>");
        sb.append("</tr>");

        int size = bdays.size();
        for (int i = 0; i < size; i++) {
            user = (MemberVO) bdays.get(i);
            DateTime dt = new DateTime(user.getDob());
            if (today == dt.getDayOfMonth()) {
                rowCss = "bgH";
            } else {
                rowCss = "portlet-section-body";
            }
            // sb.append("<tr bgcolor=\" + rowCss + \">");
            sb.append("<tr class=\"");
            sb.append(rowCss);
            sb.append("\">");
            sb.append("<td>");

            if (today == dt.getDayOfMonth()) {
                sb.append("<img src=\"" + rootContext.trim() + seperator
                        + "/images/icon/bday.jpg\" align=\"absmiddle\">");
            }
            sb.append("<a href=\"/");
            sb.append(rootContextName);
            sb.append("/action/member/displayMiniProfile?action=displayMiniProfile&memberUserName="
                    + user.getMemberUserName()
                    + "\" + onclick=\"newPopup(this.href,'name');return false\" title=\"View "
                    + user.getFirstName() + " " + user.getLastName() + " details\">" + user.getFirstName() + " "
                    + user.getLastName() + "</td>");
            sb.append("<td>" + user.getYearOut() + "</td>");
            sb.append("<td> " + StringUtil.dobPostfix(dt.getDayOfMonth()) + " of "
                    + StringUtil.convertToAlphaMonth(now.get(Calendar.MONTH) + 1) + " </td>");
            sb.append("</tr>");
        }
        if (size == 0) {
            rowCss = "portlet-section-body";
            sb.append("<tr class=\"");
            sb.append(rowCss);
            sb.append("\">");
            sb.append("<td class=\"fieldlabel\" colspan=\"3\">None.</td>");
            sb.append("</tr>");
        }
        sb.append("</table>");
    } catch (Exception ex) {
        logger.error(ex.getMessage());
        throw new JspException("IO Problem in BirthdayListTag " + ex.getMessage());
    }

    try {
        pageContext.getOut().print(sb.toString());
    } catch (Exception e) {
        logger.debug(e.getMessage());
        throw new JspException("IO Problem in BirthdayListTag " + e.getMessage());
    }

    return EVAL_PAGE;
}

From source file:forms.FormFluxodeCaixa.java

public FormFluxodeCaixa() {

    super("Fluxo de Caixa", true, true, true, true);

    // estancia o array de contas
    this.initComponents();

    //--ajustes data inicial --\\
    Calendar c = Calendar.getInstance();
    dataFinal = c.getTime();//from  www  . j  av a  2 s  .  c  om
    txtDataFinal.setDate(dataFinal);
    c.add(Calendar.DATE, -1);
    dataInicial = c.getTime();
    txtDataInicial.setDate(dataInicial);
    tipo = TipoGrafico.barras;
    titulo = "Grafico de Barras";
    // - Final ajuste data inicial -\\

    this.contas = this.buscarconta.ListarTodos(dataInicial, dataFinal);

    verificaTipoGrafico(TipoConta.ambos, 1, FiltroData.Mensal);

    grapBarras.setSelected(true);
    grapBarras.setIcon(Utils.getImage(Utils.Image.barraMarcado));

    // Marca as CheckBox \\
    checkbox_Grafico.setSelected(true);
    checkbox_Lista.setSelected(true);
    checkboxEntrada.setSelected(true);
    checkboxSaida.setSelected(true);

    if (new FlxcxFluxoCaixaFechamentoDAO().verificaLancamentoInicial()) {

        btnAdd.setVisible(false);

    } else {

        btnAdd.setVisible(true);
    }

    //        this.webPanel_Tabela.setSortable(true);
    //        this.webPanel_Tabela.setLoadMore(x -> new FormFluxodeCaixa.CarregarContas().execute());
    //
    //        new CarregarContas().execute();
}