Example usage for java.text DateFormat getDateInstance

List of usage examples for java.text DateFormat getDateInstance

Introduction

In this page you can find the example usage for java.text DateFormat getDateInstance.

Prototype

public static final DateFormat getDateInstance() 

Source Link

Document

Gets the date formatter with the default formatting style for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:de.adesso.referencer.search.helper.MyHelpMethods.java

public static String Date2String(Date date) {
    if (date == null) {
        return null;
    }/*from   w  w  w . ja v a2  s  . c  om*/
    return DateFormat.getDateInstance().format(date);
}

From source file:com.physphil.android.restaurantroulette.RestaurantSelectorFragment.java

/**
 * Use values of mRestaurant and mHistory to set answer.  If objects are null then answer fields are hidden
 * @param addToHistory whether to add this selection to selection history
 *//*from   w  w w  .  j a  va2  s .c om*/
private void setAnswer(boolean addToHistory) {

    if (mRestaurant != null) {

        rlAnswer.setVisibility(View.VISIBLE);
        btnSelectRestaurant.setText(R.string.restaurant_selector_button_pick_another);
        tvAnswer.setText(mRestaurant.getName());
        rbRating.setRating(mRestaurant.getUserRating());
        rbPrice.setRating(mRestaurant.getPriceLevel());

        // Only show Get Directions button if restaurant has a valid name to search for
        if (mRestaurant.hasName()) {
            btnGetDirections.setVisibility(View.VISIBLE);
        } else {
            btnGetDirections.setVisibility(View.GONE);
        }

        if (mHistory.size() > 0) {

            // set summary fields
            setSummaryFieldsVisibility(true);
            tvNumberOfVisits.setText(Integer.toString(mHistory.size()));

            // Objects returned from db sorted by date. Entry 0 is the most recent
            Date recentVisit = mHistory.get(0).getDate();
            DateFormat df = DateFormat.getDateInstance();
            tvLastVisit.setText(df.format(recentVisit));
        } else {

            // Hide summary fields
            setSummaryFieldsVisibility(false);
        }

        // Add selection to history
        if (addToHistory) {
            mDatabaseHelper.addRestaurantHistory(mRestaurant.getRestaurantId());
        }
    } else {

        // No answer
        rlAnswer.setVisibility(View.INVISIBLE);
        btnGetDirections.setVisibility(View.GONE);
        btnSelectRestaurant.setText(R.string.restaurant_selector_button);
    }
}

From source file:op.care.prescription.DlgOnDemand.java

private void rbDateItemStateChanged(ItemEvent e) {
    txtOFF.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
    if (e.getStateChange() == ItemEvent.SELECTED) {
        txtOFF.setText(DateFormat.getDateInstance().format(new Date()));
    }/*from  w w  w .  j  a v a 2s . c om*/
}

From source file:org.apache.hadoop.hive.ql.optimizer.calcite.druid.DruidIntervalUtils.java

private static Long toLong(Object literal) {
    if (literal instanceof Number) {
        return ((Number) literal).longValue();
    }//  w  w  w  .java  2s. co  m
    if (literal instanceof Date) {
        return ((Date) literal).getTime();
    }
    if (literal instanceof Timestamp) {
        return ((Timestamp) literal).getTime();
    }
    if (literal instanceof String) {
        try {
            return Long.valueOf((String) literal);
        } catch (NumberFormatException e) {
            // ignore
        }
        try {
            return DateFormat.getDateInstance().parse((String) literal).getTime();
        } catch (ParseException e) {
            // best effort. ignore
        }
    }
    return null;
}

From source file:op.care.supervisor.PnlHandover.java

private void expandDay(LocalDate day) {
    final String keyYear = Integer.toString(day.getYear()) + ".year";
    if (cpMap.containsKey(keyYear) && cpMap.get(keyYear).isCollapsed()) {
        try {//from   w  w  w. j a  v a2  s  .  c  o  m
            cpMap.get(keyYear).setCollapsed(false);
        } catch (PropertyVetoException e) {
            // bah!
        }
    }
    final String keyMonth = monthFormatter.format(day.toDate()) + ".month";
    if (cpMap.containsKey(keyMonth) && cpMap.get(keyMonth).isCollapsed()) {
        try {
            cpMap.get(keyMonth).setCollapsed(false);
        } catch (PropertyVetoException e) {
            // bah!
        }
    }
    final String keyDay = DateFormat.getDateInstance().format(day.toDate());
    if (cpMap.containsKey(keyDay) && cpMap.get(keyDay).isCollapsed()) {
        try {
            cpMap.get(keyDay).setCollapsed(false);
        } catch (PropertyVetoException e) {
            // bah!
        }
    }
}

From source file:ivl.android.moneybalance.ExpenseEditorActivity.java

private void updateDate() {
    DateFormat format = DateFormat.getDateInstance();
    dateView.setText(format.format(expense.getDate().getTime()));
}

From source file:com.glaf.base.utils.ParamUtil.java

/**
 * ??//  w ww  .  jav a  2  s.  c  om
 * 
 * @param request
 * @param param
 * @param defaultNum
 * @return
 */
public static Date getDateParameter(HttpServletRequest request, String param, Date defaultNum) {
    String temp = getParameter(request, param);
    if (!"".equals(temp)) {
        Date date = defaultNum;
        try {
            date = DateFormat.getDateInstance().parse(temp);
        } catch (Exception ignored) {
        }
        return date;
    } else {
        return defaultNum;
    }
}

From source file:org.apache.calcite.adapter.druid.DruidDateTimeUtils.java

private static Long toLong(Object literal) {
    if (literal instanceof Number) {
        return ((Number) literal).longValue();
    }/*from   w  w w.j  a  v a  2s  .c o  m*/
    if (literal instanceof Date) {
        return ((Date) literal).getTime();
    }
    if (literal instanceof Timestamp) {
        return ((Timestamp) literal).getTime();
    }
    if (literal instanceof Calendar) {
        return ((Calendar) literal).getTime().getTime();
    }
    if (literal instanceof String) {
        try {
            return Long.valueOf((String) literal);
        } catch (NumberFormatException e) {
            // ignore
        }
        try {
            return DateFormat.getDateInstance().parse((String) literal).getTime();
        } catch (ParseException e) {
            // best effort. ignore
        }
    }
    return null;
}

From source file:op.care.prescription.PnlScheduleDose.java

private void initPanel() {

    tabWdh.setTitleAt(0, SYSTools.xx("misc.msg.daily"));
    tabWdh.setTitleAt(1, SYSTools.xx("misc.msg.weekly"));
    tabWdh.setTitleAt(2, SYSTools.xx("misc.msg.monthly"));

    lblLDate.setText(SYSTools.xx(internalClassID + ".lblLDate") + " ");
    lblOnThe.setText(SYSTools.xx(internalClassID + ".lblOnThe"));
    lblMonth.setText(SYSTools.xx("misc.msg.months"));
    lblEach.setText(SYSTools.xx("misc.msg.every"));
    lblEvery1.setText(SYSTools.xx("misc.msg.every"));
    lblEvery2.setText(SYSTools.xx("misc.msg.every"));
    lblWeeksAt.setText(SYSTools.xx("misc.msg.weeks") + " " + SYSTools.xx("misc.msg.atchrono"));
    lblDays.setText(SYSTools.xx("misc.msg.Days2"));

    ArrayList<Date> timelist = SYSCalendar.getTimeList();
    cmbUhrzeit.setModel(new DefaultComboBoxModel(timelist.toArray()));
    cmbUhrzeit.setRenderer(SYSCalendar.getTimeRenderer());

    String[] wdaymodel = new String[] { SYSTools.xx("misc.msg.dayOfMonth"), SYSTools.xx("misc.msg.monday"),
            SYSTools.xx("misc.msg.tuesday"), SYSTools.xx("misc.msg.wednesday"),
            SYSTools.xx("misc.msg.thursday"), SYSTools.xx("misc.msg.friday"), SYSTools.xx("misc.msg.saturday"),
            SYSTools.xx("misc.msg.sunday") };
    cmbWDay.setModel(new DefaultComboBoxModel(wdaymodel));

    lblMon.setText(SYSTools.xx("misc.msg.monday"));
    lblTue.setText(SYSTools.xx("misc.msg.tuesday"));
    lblWed.setText(SYSTools.xx("misc.msg.wednesday"));
    lblThu.setText(SYSTools.xx("misc.msg.thursday"));
    lblFri.setText(SYSTools.xx("misc.msg.friday"));
    lblSat.setText(SYSTools.xx("misc.msg.saturday"));
    lblSun.setText(SYSTools.xx("misc.msg.sunday"));

    lblVeryEarly.setText(SYSTools.xx("misc.msg.earlyinthemorning.long"));
    lblMorning.setText(SYSTools.xx("misc.msg.morning.long"));
    lblNoon.setText(SYSTools.xx("misc.msg.noon.long"));
    lblAfternoon.setText(SYSTools.xx("misc.msg.afternoon.long"));
    lblEvening.setText(SYSTools.xx("misc.msg.evening.long"));
    lblVeryLate.setText(SYSTools.xx("misc.msg.lateatnight.long"));

    txtEveryDay.setText("1");
    txtEveryWeek.setText("1");
    txtEveryMonth.setText("1");
    txtEveryWDayOfMonth.setText("1");

    //        txtEveryDay.setText(schedule.getTaeglich().toString());
    //        txtEveryWeek.setText(schedule.getWoechentlich().toString());
    //        txtEveryMonth.setText(schedule.getMonatlich().toString());
    //        txtEveryWDayOfMonth.setText(schedule.getTagNum().toString());

    tabWdh.setSelectedIndex(TAB_DAILY);//from   w w w  . java  2s . com

    if (schedule.getWoechentlich() > 0) {
        cbMon.setSelected(schedule.getMon() > 0);
        cbTue.setSelected(schedule.getTue() > 0);
        cbWed.setSelected(schedule.getWed() > 0);
        cbThu.setSelected(schedule.getThu() > 0);
        cbFri.setSelected(schedule.getFri() > 0);
        cbSat.setSelected(schedule.getSat() > 0);
        cbSun.setSelected(schedule.getSun() > 0);
        tabWdh.setSelectedIndex(TAB_WEEKLY);
    }

    if (schedule.getMonatlich() > 0) {
        if (schedule.getTagNum() > 0) {
            txtEveryWDayOfMonth.setText(Short.toString(schedule.getTagNum()));
            cmbWDay.setSelectedIndex(0);
        } else {
            if (schedule.getMon() > 0) {
                cmbWDay.setSelectedIndex(1);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getMon()));
            } else if (schedule.getTue() > 0) {
                cmbWDay.setSelectedIndex(2);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getTue()));
            } else if (schedule.getWed() > 0) {
                cmbWDay.setSelectedIndex(3);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getWed()));
            } else if (schedule.getThu() > 0) {
                cmbWDay.setSelectedIndex(4);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getThu()));
            } else if (schedule.getFri() > 0) {
                cmbWDay.setSelectedIndex(5);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getFri()));
            } else if (schedule.getSat() > 0) {
                cmbWDay.setSelectedIndex(6);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getSat()));
            } else if (schedule.getSun() > 0) {
                cmbWDay.setSelectedIndex(7);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getSun()));
            }
        }
        tabWdh.setSelectedIndex(TAB_MONTHLY);
    }

    //        jdcLDatum.setMinSelectableDate(new Date());
    //        jdcLDatum.setDate(new Date(Math.max(schedule.getLDatum().getTime(), SYSCalendar.startOfDay())));

    DateMidnight scheduleLDate = new DateMidnight(schedule.getLDatum());
    DateMidnight today = new DateMidnight();
    DateMidnight ldate = new DateMidnight(Math.max(scheduleLDate.getMillis(), today.getMillis()));
    txtLDate.setText(DateFormat.getDateInstance().format(ldate.toDate()));

    txtVeryEarly.setText(schedule.getNachtMo().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtMorning.setText(schedule.getMorgens().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtNoon.setText(schedule.getMittags().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtAfternoon.setText(schedule.getNachmittags().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtEvening.setText(schedule.getAbends().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtVeryLate.setText(schedule.getNachtAb().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtTimeDose.setText(schedule.getUhrzeitDosis().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());

    txtMorning.setBackground(SYSConst.lightblue);
    txtNoon.setBackground(SYSConst.gold7);
    txtAfternoon.setBackground(SYSConst.melonrindgreen);
    txtEvening.setBackground(SYSConst.bermuda_sand);
    txtVeryLate.setBackground(SYSConst.bluegrey);

    Date now = null;
    if (schedule.getUhrzeitDosis().compareTo(BigDecimal.ZERO) > 0) {
        splitRegularPos = 0.0d;
        now = schedule.getUhrzeit();
    } else {
        now = new Date();
        splitRegularPos = 1.0d;
    }

    for (Date zeit : timelist) {
        if (SYSCalendar.compareTime(zeit, now) >= 0) {
            now = zeit;
            break;
        }
    }
    cmbUhrzeit.setSelectedItem(now);
    lblTimeDose.setText(SYSTools.xx(internalClassID + ".lblTimeDose") + " "
            + DateFormat.getTimeInstance(DateFormat.SHORT).format(now) + " "
            + SYSTools.xx("misc.msg.Time.short"));

    panelMainComponentResized(null);
}

From source file:cl.nic.dte.util.XMLUtil.java

/**
 * Verifica si una firma XML embedida es v&aacute;lida seg&uacute;n define
 * el est&aacute;ndar XML Signature (<a
 * href="http://www.w3.org/TR/xmldsig-core/#sec-CoreValidation">Core
 * Validation</a>), y si el certificado era v&aacute;lido en la fecha dada.
 * <p>/*  w ww .j a  v  a2 s.  co m*/
 * 
 * Esta rutina <b>NO</b> verifica si el certificado embedido en
 * &lt;KeyInfo&gt; es v&aacute;lido (eso debe verificarlo con la autoridad
 * certificadora que emiti&oacute; el certificado), pero si verifica que la
 * llave utilizada para verificar corresponde a la contenida en el
 * certificado.
 * 
 * @param xml
 *            el nodo &lt;Signature&gt;
 * @param date
 *            una fecha en la que se verifica la validez del certificado
 * @return el resultado de la verificaci&oacute;n
 * 
 * @see javax.xml.crypto.dsig.XMLSignature#sign(javax.xml.crypto.dsig.XMLSignContext)
 * @see cl.nic.dte.VerifyResult
 * @see cl.nic.dte.extension.DTEDefTypeExtensionHandler
 * @see #getCertificate(XMLSignature)
 */
public static VerifyResult verifySignature(Node xml, Date date) {

    try {

        XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");
        KeyValueKeySelector ksel = new KeyValueKeySelector();

        DOMValidateContext valContext = new DOMValidateContext(ksel, xml);

        // Unmarshal the signature
        XMLSignature signature = fac.unmarshalXMLSignature(valContext);

        X509Certificate x509 = getCertificate(signature);

        // Verifica que un certificado bien embedido
        if (x509 == null) {
            return (new VerifyResult(VerifyResult.XML_SIGNATURE_WRONG, false,
                    Utilities.verificationLabels.getString("XML_SIGNATURE_ERROR_NO509")));
        }

        try {
            // Valida que en la fecha dada el certificado era va'lido
            x509.checkValidity(date);
        } catch (CertificateExpiredException e) {
            String message = Utilities.verificationLabels.getString("XML_SIGNATURE_ERROR_NOTVALID");
            message = message.replaceAll("%1", DateFormat.getDateInstance().format(date));
            message = message.replaceAll("%2", DateFormat.getDateInstance().format(x509.getNotBefore()));
            message = message.replaceAll("%3", DateFormat.getDateInstance().format(x509.getNotAfter()));
            return (new VerifyResult(VerifyResult.XML_SIGNATURE_WRONG, false, message));
        } catch (CertificateNotYetValidException e) {
            String message = Utilities.verificationLabels.getString("XML_SIGNATURE_ERROR_NOTVALID");
            message = message.replaceAll("%1", DateFormat.getDateInstance().format(date));
            message = message.replaceAll("%2", DateFormat.getDateInstance().format(x509.getNotBefore()));
            message = message.replaceAll("%3", DateFormat.getDateInstance().format(x509.getNotAfter()));
            return (new VerifyResult(VerifyResult.XML_SIGNATURE_WRONG, false, message));
        }

        return (verifySignature(signature, valContext));
    } catch (MarshalException e1) {
        return (new VerifyResult(VerifyResult.XML_SIGNATURE_WRONG, false,
                Utilities.verificationLabels.getString("XML_SIGNATURE_ERROR_UNMARSHAL") + ": "
                        + e1.getMessage()));
    }

}