Example usage for java.util Date getDate

List of usage examples for java.util Date getDate

Introduction

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

Prototype

@Deprecated
public int getDate() 

Source Link

Document

Returns the day of the month 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//from  ww  w.  j av a 2 s . co m
 * @param hourCost
 */
private void bindDateboxEndDate(final Datebox dateBoxEndDate, final HourCost hourCost) {
    Util.bind(dateBoxEndDate, new Util.Getter<Date>() {

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

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

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

From source file:org.libreplan.web.costcategories.CostCategoryCRUDController.java

/**
 * Binds Datebox "init date" to the corresponding attribute of a {@link HourCost}
 *
 * @param dateBoxInitDate/*  w  w  w  . j av a2  s. c o  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:eionet.util.Util.java

/**
 *
 * @param timestamp Milliseconds since 1 January 1970.
 *///  w w w  . j ava2 s .  c o m
public static String pdfDate(long timestamp) {

    Date date = new Date(timestamp);

    String year = String.valueOf(1900 + date.getYear());
    String month = String.valueOf(date.getMonth() + 1);
    month = (month.length() < 2) ? ("0" + month) : month;
    String day = String.valueOf(date.getDate());
    day = (day.length() < 2) ? ("0" + day) : day;

    return day + "/" + month + "/" + year;
}

From source file:eionet.util.Util.java

/**
 * A method for formatting the given timestamp into a String for history.
 *
 * @param timestamp Milliseconds since 1 January 1970.
 * @return formatted time as string in the form 2015/04/18 12:43.
 *///from w w  w.j  a va  2s  . co m
public static String historyDate(long timestamp) {

    Date date = new Date(timestamp);
    String year = String.valueOf(1900 + date.getYear());
    String month = String.valueOf(date.getMonth() + 1);
    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 = year;
    time = time + "/" + month;
    time = time + "/" + day;
    time = time + " " + hours;
    time = time + ":" + minutes;

    return time;
}

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

protected Object getDate(Object data, Map<String, Object> rule) {
    try {/*from   www .ja v  a2  s . com*/
        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;
}

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

public void testDate() {
    OpenJPAEntityManager pm = getPM(true, true);
    startTx(pm);/*from w w w.  j  a v a 2  s  .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: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 ww w. j  a  v a 2s  . com
    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:org.wso2.carbon.connector.integration.test.tsheets.TSheetsConnectorIntegrationTest.java

/**
 * Set up the environment.//from  w ww  .  ja va 2 s  .  c  o  m
 */
@BeforeClass(alwaysRun = true)
public void setEnvironment() throws Exception {

    init("tsheets-connector-1.0.2-SNAPSHOT");

    esbRequestHeadersMap.put("Accept-Charset", "UTF-8");
    esbRequestHeadersMap.put("Content-Type", "application/json");

    apiRequestHeadersMap.putAll(esbRequestHeadersMap);
    apiRequestHeadersMap.put("Authorization", "Bearer " + connectorProperties.getProperty("accessToken"));

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    Date date = new Date();
    SimpleDateFormat sdf01 = new SimpleDateFormat("yyyy-MM-dd");

    date.setDate(date.getDate() - 1);
    String timeSheetTwoEnd = sdf.format(date) + "-07:00";
    date.setMinutes(date.getMinutes() - 1);
    String timeSheetTwoStart = sdf.format(date) + "-07:00";
    date.setDate(date.getDate() - 1);
    String timeSheetOneEnd = sdf.format(date) + "-07:00";
    String listTimeSheetOneEnd = sdf01.format(date);
    date.setMinutes(date.getMinutes() - 1);
    String timeSheetOneStart = sdf.format(date) + "-07:00";
    String listTimeSheetOneStart = sdf01.format(date);
    connectorProperties.setProperty("timeSheetOneStart", timeSheetOneStart);
    connectorProperties.setProperty("timeSheetOneEnd", timeSheetOneEnd);
    connectorProperties.setProperty("timeSheetTwoStart", timeSheetTwoStart);
    connectorProperties.setProperty("timeSheetTwoEnd", timeSheetTwoEnd);
    connectorProperties.setProperty("listTimeSheetOneStart", listTimeSheetOneStart);
    connectorProperties.setProperty("listTimeSheetOneEnd", listTimeSheetOneEnd);
}

From source file:com.hp.flume.plugins.spoolsource.ReliableSpoolingFileEventReader.java

/**
 * Returns the next file to be consumed from the chosen directory. If the
 * directory is empty or the chosen file is not readable, this will return
 * an absent option. If the {@link #consumeOrder} variable is
 * {@link ConsumeOrder#OLDEST} then returns the oldest file. If the
 * {@link #consumeOrder} variable is {@link ConsumeOrder#YOUNGEST} then
 * returns the youngest file. If two or more files are equally old/young,
 * then the file name with lower lexicographical value is returned. If the
 * {@link #consumeOrder} variable is {@link ConsumeOrder#RANDOM} then
 * returns any arbitrary file in the directory.
 *///from  w  ww  . ja  v a  2s  .c om
private Optional<FileInfo> getNextFile() {
    /* Filter to exclude finished or hidden files */
    FileFilter filter = new FileFilter() {
        public boolean accept(File candidate) {
            String fileName = candidate.getName();
            // lucheng
            // int date =
            // String regEx = "[a-zA-Z]+_\\d{4}_\\d{2}_(\\d{2})";
            // Pattern pat = Pattern.compile(regEx);
            //
            // Matcher mat = pat.matcher(fileName);
            // mat.find();
            // int fileDate = Integer.parseInt(mat.group(1));
            //            Matcher mat = Pattern.compile(
            //                  "[a-zA-Z]+_\\d{4}_\\d{2}_(\\d{2})").matcher(fileName);
            //            mat.find();
            Long time = candidate.lastModified();
            Date dt = new Date();
            dt.setTime(time);
            int modifiedTime = dt.getDate();
            if ((candidate.isDirectory()) || (fileName.endsWith(completedSuffix)) || (fileName.startsWith("."))
                    || ignorePattern.matcher(fileName).matches()
                    || new Date().getDate() == modifiedTime/*Integer.parseInt(mat
                                                           .group(1))*/) {
                return false;
            }
            return true;
        }
    };
    List<File> candidateFiles = Arrays.asList(spoolDirectory.listFiles(filter));
    if (candidateFiles.isEmpty()) { // No matching file in spooling directory.
        return Optional.absent();
    }

    File selectedFile = candidateFiles.get(0); // Select the first random
    // file.
    if (consumeOrder == ConsumeOrder.RANDOM) { // Selected file is random.
        return openFile(selectedFile);
    } else if (consumeOrder == ConsumeOrder.YOUNGEST) {
        for (File candidateFile : candidateFiles) {
            long compare = selectedFile.lastModified() - candidateFile.lastModified();
            if (compare == 0) { // ts is same pick smallest lexicographically.
                selectedFile = smallerLexicographical(selectedFile, candidateFile);
            } else if (compare < 0) { // candidate is younger (cand-ts > selec-ts)
                selectedFile = candidateFile;
            }
        }
    } else { // default order is OLDEST
        for (File candidateFile : candidateFiles) {
            long compare = selectedFile.lastModified() - candidateFile.lastModified();
            if (compare == 0) { // ts is same pick smallest lexicographically.
                selectedFile = smallerLexicographical(selectedFile, candidateFile);
            } else if (compare > 0) { // candidate is older (cand-ts < selec-ts).
                selectedFile = candidateFile;
            }
        }
    }

    return openFile(selectedFile);
}

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

public void testSQLDate() {
    OpenJPAEntityManager pm = getPM(true, true);
    startTx(pm);//from   w w w .j  a v  a 2  s.  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);
}