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:org.libreplan.web.costcategories.CostCategoryCRUDController.java

/**
 * Binds Datebox "init date" to the corresponding attribute of a {@link HourCost}
 *
 * @param dateBoxInitDate// ww  w.j  a va 2  s  . co m
 * @param hourCost
 */
private void bindDateboxInitDate(final Datebox dateBoxInitDate, final HourCost hourCost) {
    Util.bind(dateBoxInitDate, new Util.Getter<Date>() {

        @Override
        public Date get() {
            LocalDate dateTime = hourCost.getInitDate();
            if (dateTime != null) {
                return new Date(dateTime.getYear() - 1900, dateTime.getMonthOfYear() - 1,
                        dateTime.getDayOfMonth());
            } else {
                Date now = new Date();
                hourCost.setInitDate(new LocalDate(now));
                return now;
            }
        }

    }, new Util.Setter<Date>() {

        @Override
        public void set(Date value) {
            if (value != null) {
                hourCost.setInitDate(
                        new LocalDate(value.getYear() + 1900, value.getMonth() + 1, value.getDate()));
            } else {
                hourCost.setInitDate(null);
            }
        }
    });
}

From source file:org.apache.openjpa.persistence.kernel.TestProxies2.java

public void testDate() {
    OpenJPAEntityManager pm = getPM(true, true);
    startTx(pm);//from ww w.  j ava 2s. c  o  m
    ProxiesPC pc = pm.find(ProxiesPC.class, _oid);
    Date date = pc.getDate();
    assertNotNull(date);

    // dates can lose precision, but make sure same day
    assertEquals(_date.getYear(), date.getYear());
    assertEquals(_date.getMonth(), date.getMonth());
    assertEquals(_date.getDate(), date.getDate());

    // make sure proxied
    assertTrue(!pm.isDirty(pc));
    date.setTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24);
    assertTrue(pm.isDirty(pc));

    endTx(pm);
    assertEquals(date, pc.getDate());
    endEm(pm);
}

From source file:org.apache.openjpa.persistence.kernel.TestProxies2.java

public void testSQLDate() {
    OpenJPAEntityManager pm = getPM(true, true);
    startTx(pm);//from   w w w .  ja v  a2s.  c o m
    ProxiesPC pc = pm.find(ProxiesPC.class, _oid);
    java.sql.Date date = pc.getSQLDate();
    assertNotNull(date);

    // dates can lose precision, but make sure same day
    assertEquals(_sqlDate.getYear(), date.getYear());
    assertEquals(_sqlDate.getMonth(), date.getMonth());
    assertEquals(_sqlDate.getDate(), date.getDate());

    // make sure proxied
    assertTrue(!pm.isDirty(pc));
    date.setTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24);
    assertTrue(pm.isDirty(pc));

    endTx(pm);
    assertEquals(date, pc.getSQLDate());
    endEm(pm);
}

From source file:br.com.nverse.sac.controllers.NewClienteCtrl.java

private void inicializarVariaveis() {

    Date data = this.cliente.getDataCadastro();
    String mes = data.getMonth() < 10 ? "0" + data.getMonth() : data.getMonth() + "";
    int ano = data.getYear() + 1900;
    String dia = data.getDate() < 10 ? "0" + data.getDate() : data.getDate() + "";
    dataCadastro = dia + "/" + mes + "/" + ano;

    agregadoAtual = new Agregado();
    veiculo = new Veiculo();
    representante = new Representante();
    contrato = new Contrato();
    historiaAtual = new Historico();
}

From source file:com.vkassin.mtrade.Common.java

public static void putArcDeal(final Context ctx) {

    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.arcdeal_dialog);
    dialog.setTitle(R.string.ArcDealDialogTitle);

    datetxt = (EditText) dialog.findViewById(R.id.expdateedit);
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    Date dat1 = new Date();
    datetxt.setText(sdf.format(dat1));/*from  w ww. j  a v  a  2 s .  c  om*/
    mYear = dat1.getYear() + 1900;
    mMonth = dat1.getMonth();
    mDay = dat1.getDate();
    final Date dat = new GregorianCalendar(mYear, mMonth, mDay).getTime();

    datetxt.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.i(TAG, "Show DatePickerDialog");
            DatePickerDialog dpd = new DatePickerDialog(ctx, mDateSetListener, mYear, mMonth, mDay);
            dpd.show();
        }
    });

    TextView itext = (TextView) dialog.findViewById(R.id.instrtext);
    itext.setText(Common.arcfilter);

    Button customDialog_Cancel = (Button) dialog.findViewById(R.id.cancelbutt);
    customDialog_Cancel.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            dialog.dismiss();
        }

    });

    Button customDialog_Put = (Button) dialog.findViewById(R.id.putorder);
    customDialog_Put.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            Double price = new Double(0);
            Long qval = new Long(0);
            final EditText pricetxt = (EditText) dialog.findViewById(R.id.priceedit);
            final EditText quanttxt = (EditText) dialog.findViewById(R.id.quantedit);

            try {

                price = Double.valueOf(pricetxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show();
                return;
            }
            try {

                qval = Long.valueOf(quanttxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show();
                return;
            }

            //            if (dat.compareTo(new GregorianCalendar(mYear, mMonth, mDay)
            //            .getTime()) > 0) {
            //
            //               Toast.makeText(ctx, R.string.CorrectDate,
            //               Toast.LENGTH_SHORT).show();
            //
            //            return;
            //            }

            long maxkey = 0;
            Iterator<String> itr2 = arcdealMap.keySet().iterator();
            while (itr2.hasNext()) {
                String key1 = itr2.next();
                long k = Long.parseLong(key1);
                if (k > maxkey)
                    maxkey = k;
            }

            Deal adeal = new Deal();
            Iterator<String> itr1 = instrMap.keySet().iterator();
            while (itr1.hasNext()) {
                String key1 = itr1.next();
                Instrument in = instrMap.get(key1);
                if (in.symbol.equals(Common.arcfilter)) {

                    adeal.instrId = Long.valueOf(in.id);
                    break;
                }
            }

            final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.radio0);

            adeal.price = price;
            adeal.qty = qval;
            adeal.dtime = new GregorianCalendar(mYear, mMonth, mDay).getTimeInMillis();
            adeal.direct = bu0.isChecked() ? Long.valueOf(0) : Long.valueOf(1);
            Collection<String> lacc = Common.getAccountList();
            adeal.account = (lacc == null) ? "" : lacc.iterator().next();
            arcdealMap.put(String.valueOf(maxkey + 1), adeal);
            Common.saveArcDeals();
            Common.arcActivity.refresh();
            dialog.dismiss();
        }
    });

    dialog.show();

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.FILL_PARENT;
    dialog.getWindow().setAttributes(lp);

}

From source file:com.edgenius.wiki.blogsync.WordpressProxy.java

/**
 * Return "date_create_gmt" time is gmt, but timezone is wrong - it is local timezone. 
 * Here will correct timezone and return date in local timezone.
 * @param date/*from w  w  w.  j  a  v a  2s  . co m*/
 * @return
 */
private Date fixInputTimezone(Date date) {
    if (date == null)
        return new Date();//???

    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    cal.set(Calendar.YEAR, date.getYear() + 1900);
    cal.set(Calendar.MONTH, date.getMonth());
    cal.set(Calendar.DATE, date.getDate());
    cal.set(Calendar.HOUR_OF_DAY, date.getHours());
    cal.set(Calendar.MINUTE, date.getMinutes());
    cal.set(Calendar.SECOND, date.getSeconds());

    Calendar local = Calendar.getInstance(TimeZone.getDefault());
    local.setTimeInMillis(cal.getTimeInMillis());
    return local.getTime();
}

From source file:org.nerve.utils.StringUtils.java

/**
 * ???/*from  www  .j av  a2  s. c om*/
 *
 * @param time      
 * @return
 */
public static String processTime(Long time) {
    long oneDay = 24 * 60 * 60 * 1000;
    Date now = new Date();
    Date orginalTime = new Date(time);
    long nowDay = now.getTime() - (now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds()) * 1000;
    long yesterday = nowDay - oneDay;
    String nowHourAndMinute = toDoubleDigit(orginalTime.getHours()) + ":"
            + toDoubleDigit(orginalTime.getMinutes());
    if (time >= now.getTime()) {
        return "";
    } else if ((now.getTime() - time) < (60 * 1000)) {
        return (now.getTime() - time) / 1000 + "? " + nowHourAndMinute + " ";
    } else if ((now.getTime() - time) < (60 * 60 * 1000)) {
        return (now.getTime() - time) / 1000 / 60 + "? " + nowHourAndMinute + " ";
    } else if ((now.getTime() - time) < (24 * 60 * 60 * 1000)) {
        return (now.getTime() - time) / 1000 / 60 / 60 + "?? " + nowHourAndMinute + " ";
    } else if (time >= nowDay) {
        return " " + nowHourAndMinute;
    } else if (time >= yesterday) {
        return " " + nowHourAndMinute;
    } else {
        return toDoubleDigit(orginalTime.getMonth()) + "-" + toDoubleDigit(orginalTime.getDate()) + " "
                + nowHourAndMinute + ":" + toDoubleDigit(orginalTime.getSeconds());
    }
}

From source file:org.openmrs.module.laboratorymanagement.web.chart.EvolutionOfClientRegisteredPerDay.java

/**
 * Auto generated method comment/*from  ww w.  j a v  a 2s. c  o  m*/
 * 
 * @return
 */
private CategoryDataset createDataset(String patientIdstr, String locationIdstr, int conceptId, Date startDate,
        Date endDate) {

    // row keys...
    Calendar ca1 = Calendar.getInstance();
    String series1 = Context.getConceptService().getConcept(conceptId).getDisplayString();
    // Date format declaration
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    List<Obs> testTakenBetweenTwoDates = null;
    LaboratoryService labService = Context.getService(LaboratoryService.class);

    int startMonths = startDate.getMonth() + 1;
    int endMonth = endDate.getMonth() + 1;

    int startYear = startDate.getYear() + 1900;
    int endYear = endDate.getYear() + 1900;

    // create the dataset...
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if (startYear == endYear) {

        for (int months = startMonths; months <= endMonth; months = months + 1) {

            try {
                if (months == startMonths) {
                    // populate the map
                    Date startDat = startDate;
                    ca1.set(startYear, months - 1, 1);
                    Date d = new java.util.Date(ca1.getTimeInMillis());
                    Date endDat = LaboratoryMgt.getLastDayOfMonth(startYear, months - 1);
                    List<Obs> allTestWithResult = LaboratoryMgt.getAllLabTestByCriteria(patientIdstr,
                            locationIdstr, conceptId, startDat, endDat);
                    testTakenBetweenTwoDates = LaboratoryMgt.getAllTestWithSpecificConcept(allTestWithResult,
                            conceptId);

                    int value = testTakenBetweenTwoDates.size();
                    dataset.addValue(value, series1, "" + new SimpleDateFormat("MMMM").format(d));
                    continue;

                }
                if (months == endMonth) {
                    ca1.set(startYear, months - 1, 1);
                    Date d = new java.util.Date(ca1.getTimeInMillis());
                    Date startDat = df.parse("01/" + months + "/" + startYear);
                    Date endDat = endDate;
                    List<Obs> allTestWithResult = LaboratoryMgt.getAllLabTestByCriteria(patientIdstr,
                            locationIdstr, conceptId, startDat, endDat);

                    testTakenBetweenTwoDates = LaboratoryMgt.getAllTestWithSpecificConcept(allTestWithResult,
                            conceptId);
                    int value = testTakenBetweenTwoDates.size();
                    dataset.addValue(value, series1, "" + new SimpleDateFormat("MMMM").format(d));
                    continue;
                }
                Date startDat = df.parse("01/" + months + "/" + startYear);
                ca1.set(startYear, months - 1, 1);
                Date d = new java.util.Date(ca1.getTimeInMillis());
                Date endDat = LaboratoryMgt.getLastDayOfMonth(startYear, months - 1);
                List<Obs> allTestWithResult = LaboratoryMgt.getAllLabTestByCriteria(patientIdstr, locationIdstr,
                        conceptId, startDat, endDat);
                testTakenBetweenTwoDates = LaboratoryMgt.getAllTestWithSpecificConcept(allTestWithResult,
                        conceptId);
                int value = testTakenBetweenTwoDates.size();
                dataset.addValue(value, series1, "" + new SimpleDateFormat("MMMM").format(d));

            } catch (Exception e) {
                // TODO: handle exception
            }

        }
    }
    if (startYear != endYear) {
        for (int year = startYear; year <= endYear; year = year + 1) {
            try {

                if (year == startYear) {

                    Date startDat = startDate;
                    Date endDat = df.parse("31/12/" + year);

                    List<Obs> allTestWithResult = LaboratoryMgt.getAllLabTestByCriteria(patientIdstr,
                            locationIdstr, conceptId, startDat, endDat);

                    testTakenBetweenTwoDates = LaboratoryMgt.getAllTestWithSpecificConcept(allTestWithResult,
                            conceptId);
                    int value = testTakenBetweenTwoDates.size();
                    dataset.addValue(value, series1, "" + year);

                    continue;

                }
                if (year == endYear) {
                    Date startDat = df.parse("01/01/" + year);
                    Date endDat = endDate;

                    List<Obs> allTestWithResult = LaboratoryMgt.getAllLabTestByCriteria(patientIdstr,
                            locationIdstr, conceptId, startDat, endDat);

                    testTakenBetweenTwoDates = LaboratoryMgt.getAllTestWithSpecificConcept(allTestWithResult,
                            conceptId);
                    int value = testTakenBetweenTwoDates.size();
                    dataset.addValue(value, series1, "" + year);

                    continue;

                }
                Date startDat = df.parse("01/01/" + year);
                Date endDat = df.parse("31/12/" + year);

                List<Obs> allTestWithResult = LaboratoryMgt.getAllLabTestByCriteria(patientIdstr, locationIdstr,
                        conceptId, startDat, endDat);

                testTakenBetweenTwoDates = LaboratoryMgt.getAllTestWithSpecificConcept(allTestWithResult,
                        conceptId);
                int value = testTakenBetweenTwoDates.size();
                dataset.addValue(value, series1, "" + year);
                continue;

            } catch (Exception e) {
                // TODO: handle exception
            }

        }
    }
    return dataset;

}

From source file:com.krawler.common.util.StringUtil.java

public static Boolean issameDatesExTime(Date olddate, String newdatestr) {
    Date newdate = new Date(newdatestr);
    return newdate.getDate() == olddate.getDate() && newdate.getYear() == olddate.getYear()
            && newdate.getMonth() == olddate.getMonth();
}

From source file:org.ms123.common.data.query.MVELSelectBuilder.java

protected Object getDate(Object data, Map<String, Object> rule) {
    try {/*from   ww  w  .  j a  v  a2s. c  o m*/
        Date d = new Date();
        try {
            if (data instanceof Long) {
                d = new Date((Long) data);
            } else {
                d = new Date(Long.valueOf((String) rule.get("data")));
            }
        } catch (Exception e) {
        }
        String op = (String) rule.get("op");
        if (op.equals("eq") || op.equals("ceq") || op.equals("neq")) {
            String day = d.getDate() + "";
            String month = d.getMonth() + "";
            String year = (d.getYear()) + "";
            data = day + "/" + month + "/" + year;
        } else {
            int paramCount = m_queryBuilder.getParamCount();
            data = "param" + paramCount;
            m_queryBuilder.getQueryParams().put("param" + paramCount, d);
            m_queryBuilder.incParamCount();
        }
    } catch (Exception e) {
        e.printStackTrace();
        data = "''";
    }
    return data;
}