Example usage for java.util Date getMonth

List of usage examples for java.util Date getMonth

Introduction

In this page you can find the example usage for java.util Date getMonth.

Prototype

@Deprecated
public int getMonth() 

Source Link

Document

Returns a number representing the month that contains or begins with the instant in time represented by this Date object.

Usage

From source file:eionet.util.Util.java

/**
 * A method for calculating and formatting the current date and time into a String for a log.
 *//*from   w  ww .  j  av  a 2 s. co  m*/

public static String logTime() {

    Date date = new Date();
    String month = String.valueOf(date.getMonth());
    month = (month.length() < 2) ? ("0" + month) : month;
    String day = String.valueOf(date.getDate());
    day = (day.length() < 2) ? ("0" + day) : day;
    String hours = String.valueOf(date.getHours());
    hours = (hours.length() < 2) ? ("0" + hours) : hours;
    String minutes = String.valueOf(date.getMinutes());
    minutes = (minutes.length() < 2) ? ("0" + minutes) : minutes;
    String seconds = String.valueOf(date.getSeconds());
    seconds = (seconds.length() < 2) ? ("0" + seconds) : seconds;

    String time = "[" + month;
    time = time + "/" + day;
    time = time + " " + hours;
    time = time + ":" + minutes;
    time = time + ":" + seconds;
    time = time + "] ";

    return time;
}

From source file:team.curise.controller.mana.service.EngageService.java

public void sortDepartMonthRevenue(List<DepartMonthRevenue> list) {
    Collections.sort(list, new Comparator<DepartMonthRevenue>() {
        @Override// ww  w . jav a2s .  c  o m
        public int compare(DepartMonthRevenue o1, DepartMonthRevenue o2) {
            try {
                if (o1 != null && o2 != null) {
                    Date date1 = DateUtil.stringToDate(o1.getDate());
                    Date date2 = DateUtil.stringToDate(o2.getDate());
                    int month1 = date1.getMonth();
                    int month2 = date2.getMonth();
                    Calendar c = Calendar.getInstance();
                    c.setTime(date1);
                    int year1 = c.get(Calendar.YEAR);
                    c.setTime(date2);
                    int year2 = c.get(Calendar.YEAR);
                    if (year1 > year2) {
                        return 1;
                    } else if (year1 == year2) {
                        if (month1 > month2) {
                            return 1;
                        } else if (month1 < month2) {
                            return -1;
                        }
                        return 0;
                    }
                }

            } catch (ParseException ex) {
                Logger.getLogger(EngageManaController.class.getName()).log(Level.SEVERE, null, ex);
            }
            return -1;
        }
    });
}

From source file:org.springframework.extensions.webscripts.json.JSONUtils.java

/**
 * Convert value to JSON string/*from   w  w w .  j ava  2  s . co m*/
 * 
 * @param value         Java object value
 * @param writer    JSONWriter for output stream
 * @throws IOException 
 */
private void valueToJSONString(Object value, JSONWriter writer) throws IOException {
    if (value instanceof IdScriptableObject && TYPE_DATE.equals(((IdScriptableObject) value).getClassName())) {
        Date date = (Date) Context.jsToJava(value, Date.class);

        // Build the JSON object to represent the UTC date
        writer.startObject().writeValue("zone", "UTC").writeValue("year", date.getYear())
                .writeValue("month", date.getMonth()).writeValue("date", date.getDate())
                .writeValue("hours", date.getHours()).writeValue("minutes", date.getMinutes())
                .writeValue("seconds", date.getSeconds()).writeValue("milliseconds", date.getTime())
                .endObject();
    } else if (value instanceof NativeJavaObject) {
        // extract the underlying Java object and recursively output
        Object javaValue = Context.jsToJava(value, Object.class);
        valueToJSONString(javaValue, writer);
    } else if (value instanceof NativeArray) {
        // Output the native object
        nativeArrayToJSONString((NativeArray) value, writer);
    } else if (value instanceof NativeObject) {
        // Output the native array
        nativeObjectToJSONString((NativeObject) value, writer);
    } else if (value instanceof Number) {
        if (value instanceof Integer || value instanceof Long) {
            writer.writeValue(((Number) value).longValue());
        } else if (value instanceof Double) {
            writer.writeValue(((Number) value).doubleValue());
        } else if (value instanceof Float) {
            writer.writeValue(((Number) value).floatValue());
        } else {
            writer.writeValue(((Number) value).doubleValue());
        }
    } else if (value instanceof Boolean) {
        writer.writeValue(((Boolean) value).booleanValue());
    } else if (value instanceof Map) {
        writer.startObject();
        for (Object key : ((Map) value).keySet()) {
            writer.startValue(key.toString());
            valueToJSONString(((Map) value).get(key), writer);
            writer.endValue();
        }
        writer.endObject();
    } else if (value instanceof List) {
        writer.startArray();
        for (Object val : (List) value) {
            valueToJSONString(val, writer);
        }
        writer.endArray();
    } else if (value != null) {
        writer.writeValue(value.toString());
    } else {
        writer.writeNullValue();
    }
}

From source file:team.curise.controller.mana.service.EngageService.java

public List<RevenueMonth> getRoomRevenueOnMonth(int curise_id) throws ParseException {
    List<RevenueMonth> l = new ArrayList<>();
    Calendar calendar = Calendar.getInstance();
    int nowMonth = calendar.get(Calendar.MONTH) + 1;
    int nowYear = calendar.get(Calendar.YEAR);
    List<RoomMonthRevenue> r = getMonthRoomRevenueByCuriseId(curise_id);
    sortRoomMonthRevenue(r);/*w w  w. j  av  a  2 s  . com*/
    for (RoomMonthRevenue rmr : r) {
        String datetime = rmr.getDate();
        Date date = DateUtil.stringToDate(datetime);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int year = c.get(Calendar.YEAR);
        int month = date.getMonth() + 1;//??month0
        if ((month <= nowMonth && year == nowYear) || (month > nowMonth && year == (nowYear - 1))) {
            double revenue = rmr.getRevenue();
            RevenueMonth revenueMonth = new RevenueMonth(month, revenue);
            l.add(revenueMonth);
        }
    }
    return l;
}

From source file:team.curise.controller.mana.service.EngageService.java

public List<RevenueMonth> getDepartRevenueOnMonth(int curise_id, int depart_id) throws ParseException {
    List<RevenueMonth> l = new ArrayList<>();
    Calendar calendar = Calendar.getInstance();
    int nowMonth = calendar.get(Calendar.MONTH) + 1;
    int nowYear = calendar.get(Calendar.YEAR);
    //??????//from  w  w  w .j  a va2s .c om
    List<DepartMonthRevenue> r = getMonthRevenueByCuriseIdAndDId(curise_id, depart_id);
    sortDepartMonthRevenue(r);
    for (DepartMonthRevenue d : r) {
        String datetime = d.getDate();
        Date date = DateUtil.stringToDate(datetime);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int year = c.get(Calendar.YEAR);
        int month = date.getMonth() + 1;//??month0
        if ((month <= nowMonth && year == nowYear) || (month > nowMonth && year == (nowYear - 1))) {
            double revenue = d.getRevenue();
            RevenueMonth revenueMonth = new RevenueMonth(month, revenue);
            l.add(revenueMonth);
        }
    }
    return l;
}

From source file:com.progym.custom.fragments.FoodCalloriesProgressYearlyLineFragment.java

public void setYearProgressData(Date date) {
    int yMaxAxisValue = 0;
    try {/*from ww  w.  j  a v a 2s .c o  m*/
        rlRootGraphLayout.removeView(viewChart);
    } catch (Exception edsx) {
        edsx.printStackTrace();
    }
    DATE = date;
    // Get amount of days in a month to find out average
    int daysInMonth = Utils.getDaysInMonth(date.getMonth(),
            Integer.valueOf(Utils.formatDate(date, DataBaseUtils.DATE_PATTERN_YYYY)));
    // set January as first month
    date.setMonth(0);
    date.setDate(1);

    int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };

    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    CategorySeries seriesCallories = new CategorySeries("Callories");

    List<Ingridient> list;
    for (int i = 0; i < x.length; i++) {
        list = DataBaseUtils
                .getAllFoodConsumedInMonth(Utils.formatDate(date, DataBaseUtils.DATE_PATTERN_YYYY_MM));

        // init "average" data
        int totalCallories = 0;
        for (Ingridient ingridient : list) {
            totalCallories += ingridient.kkal;
        }
        // add value to series
        seriesCallories.add(totalCallories / daysInMonth);
        // calculate maximum Y axis values
        yMaxAxisValue = Math.max(yMaxAxisValue, totalCallories / daysInMonth);
        // increment month
        date = DateUtils.addMonths(date, 1);
    }

    int[] colors = new int[] { getActivity().getResources().getColor(R.color.purple) };
    XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
    setChartSettings(renderer,
            String.format("Callories statistic for %s year", Utils.getSpecificDateValue(DATE, "yyyy")),
            "Months", "Amount (g)", 0.7, 12.3, 0, yMaxAxisValue + 30, Color.GRAY, Color.LTGRAY);

    renderer.getSeriesRendererAt(0).setDisplayChartValues(true);
    renderer.getSeriesRendererAt(0).setChartValuesTextSize(15f);
    renderer.setXLabels(0);
    renderer.setClickEnabled(false);
    renderer.setZoomEnabled(false);
    renderer.setPanEnabled(false, false);
    renderer.setZoomButtonsVisible(false);
    renderer.setPanLimits(new double[] { 1, 11 });
    renderer.setShowGrid(true);
    renderer.setShowLegend(true);
    renderer.setFitLegend(true);

    for (int i = 0; i < ActivityWaterProgress.months_short.length; i++) {
        renderer.addXTextLabel(i + 1, ActivityWaterProgress.months_short[i]);

    }
    dataset.addSeries(seriesCallories.toXYSeries());

    viewChart = ChartFactory.getBarChartView(getActivity(), dataset, renderer, Type.DEFAULT);
    rlRootGraphLayout.addView(viewChart, 0);
}

From source file:team.curise.controller.mana.service.EngageService.java

public List<RevenueQuarter> getRoomRevenueOnQuarter(int curise_id) throws ParseException {
    List<RevenueQuarter> l = new ArrayList<>();
    Calendar calendar = Calendar.getInstance();
    int nowMonth = calendar.get(Calendar.MONTH) + 1;
    int nowYear = calendar.get(Calendar.YEAR);
    List<RoomMonthRevenue> r = getMonthRoomRevenueByCuriseId(curise_id);
    sortRoomMonthRevenue(r);// w ww .  j  a  va  2  s .c o  m
    int quarter = 1;
    int i = 0;
    double nowQuarter = 0;
    for (RoomMonthRevenue d : r) {
        String datetime = d.getDate();
        Date date = DateUtil.stringToDate(datetime);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int year = c.get(Calendar.YEAR);
        int month = date.getMonth() + 1;//??month0

        if (month <= nowMonth && year == nowYear) {
            i++;
            nowQuarter += d.getRevenue();
            if (i == 3) {
                RevenueQuarter q = new RevenueQuarter(quarter, nowQuarter);
                l.add(q);
                i = 0;
                nowQuarter = 0;
                quarter++;
            }

        }
    }
    return l;
}

From source file:team.curise.controller.mana.service.EngageService.java

public List<RevenueQuarter> getDepartRevenueOnQuarter(int curise_id, int depart_id) throws ParseException {
    List<RevenueQuarter> l = new ArrayList<>();
    Calendar calendar = Calendar.getInstance();
    int nowMonth = calendar.get(Calendar.MONTH) + 1;
    int nowYear = calendar.get(Calendar.YEAR);
    //??????/*  w  ww.j  a va  2  s.c  om*/
    List<DepartMonthRevenue> r = getMonthRevenueByCuriseIdAndDId(curise_id, depart_id);
    sortDepartMonthRevenue(r);
    int quarter = 1;
    int i = 0;
    double nowQuarter = 0;
    for (DepartMonthRevenue d : r) {
        String datetime = d.getDate();
        Date date = DateUtil.stringToDate(datetime);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int year = c.get(Calendar.YEAR);
        int month = date.getMonth() + 1;//??month0

        if (month <= nowMonth && year == nowYear) {
            i++;
            nowQuarter += d.getRevenue();
            if (i == 3) {
                RevenueQuarter q = new RevenueQuarter(quarter, nowQuarter);
                l.add(q);
                i = 0;
                nowQuarter = 0;
                quarter++;
            }

        }
    }
    return l;
}

From source file:com.agroservices.logic.entidadBancariaFacade.java

public boolean validarTarjeta(informacionTarjeta tarjeta) {

    Date fecha = new Date();
    boolean respuesta = true;

    if (tarjeta.getNumero() % 2 != 0) {
        System.out.println("Numero tarjeta: " + tarjeta.getNumero() + " Modulo: " + tarjeta.getNumero() % 2);
        respuesta = false;//from w w  w. j  av  a2s .  c o  m
    }

    if (tarjeta.getAnoVencimiento() < (fecha.getYear() + 1900)) {

        System.out.println("Ao tarjeta: " + tarjeta.getAnoVencimiento() + " Ao de la fecha: "
                + fecha.getYear() + 1900);
        respuesta = false;
    }

    if (tarjeta.getMesVencimiento() < (fecha.getMonth() + 1)
            && (tarjeta.getAnoVencimiento() == (fecha.getYear() + 1900))) {

        System.out.println("mes tarjeta: " + tarjeta.getMesVencimiento() + " Modulo: " + fecha.getMonth() + 1);
        respuesta = false;
    }

    return respuesta;
}

From source file:org.openmrs.module.vcttrac.web.controller.VCTTracnetIndicatorsController.java

/**
 * Auto generated method comment/*from  w  w  w. j  a  va 2  s  . c  o  m*/
 * 
 * @param request
 * @param response
 * @param mav
 */
private void mapParameters(HttpServletRequest request, HttpServletResponse response, ModelAndView mav) {
    DateFormat df = Context.getDateFormat();
    try {
        Date today = new Date();
        if (request.getParameter("location") == null || request.getParameter("location").compareTo("") == 0)
            mav.addObject("defaultLoc", VCTConfigurationUtil.getDefaultLocationId());
        else
            mav.addObject("defaultLoc", request.getParameter("location"));

        if (request.getParameter("dateFrom") == null || request.getParameter("dateFrom").compareTo("") == 0)
            mav.addObject("from", df.format(new Date(today.getYear(), today.getMonth(), 1)));
        else
            mav.addObject("from", request.getParameter("dateFrom"));

        if (request.getParameter("dateTo") == null || request.getParameter("dateTo").compareTo("") == 0)
            mav.addObject("to", df.format(today));
        else
            mav.addObject("to", request.getParameter("dateTo"));

        //         VCTModuleService vms=Context.getService(VCTModuleService.class);
        //         vms.getCouplesCounseledAndTested(request.getParameter("dateFrom"), request.getParameter("dateTo"), VCTConfigurationUtil.getDefaultLocationId());

    } catch (Exception e) {
        request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR,
                getMessageSourceAccessor().getMessage("@MODULE_ID@.error.loadingData"));
        log.error(">>>>>>VCT>>TRACNET>>INDICATORS>> " + e.getMessage());
        e.printStackTrace();
    }
}