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:com.haulmont.chile.core.datatypes.impl.DateDatatype.java

@Override
public String format(Object value) {
    if (value == null) {
        return "";
    }//from w w w  .  j  a  v a2 s .  c  o m

    DateFormat format;
    if (formatPattern != null) {
        format = new SimpleDateFormat(formatPattern);
    } else {
        format = DateFormat.getDateInstance();
    }
    return format.format((value));
}

From source file:ejava.projects.edmv.xml.EDmvBindingTest.java

public void testCalendar() throws Exception {
    log.info("*** testCalendar ***");
    DatatypeFactory dataFactory = DatatypeFactory.newInstance();
    log.info("DataTypeFactory=" + dataFactory);
    XMLGregorianCalendar cal = dataFactory.newXMLGregorianCalendar();
    log.info("XMLGregorianCalendar=" + cal.getClass());
    cal.setMonth(GregorianCalendar.MARCH);
    String xml = cal.toXMLFormat();
    log.debug("cal=" + xml);
    dataFactory.newXMLGregorianCalendar(xml);

    cal.setTimezone(0);//from www .jav a  2  s .c o m

    Calendar jCal = Calendar.getInstance();
    jCal.clear();
    jCal.set(Calendar.MONTH, Calendar.MARCH);
    DateFormat df = DateFormat.getDateInstance();
    String dfString = df.format(jCal.getTime());
    log.debug("calendar=" + dfString);

    String format = "--01";
    try {
        XMLGregorianCalendar xCal = dataFactory.newXMLGregorianCalendar(format);
        log.info("successfully parsed:" + format + ", xCal=" + xCal.toXMLFormat());
        format = "--01--";
        xCal = dataFactory.newXMLGregorianCalendar(format);
        log.info("successfully parsed:" + format + ", xCal=" + xCal.toXMLFormat());
    } catch (Exception ex) {
        log.error("failed to parse:" + format);
        fail("failed to parse:" + format);
    }
}

From source file:FieldValidator.java

private static JComponent createContent() {
    Dimension labelSize = new Dimension(80, 20);

    Box box = Box.createVerticalBox();

    // A single LayerUI for all the fields.
    LayerUI<JFormattedTextField> layerUI = new ValidationLayerUI();

    // Number field.
    JLabel numberLabel = new JLabel("Number:");
    numberLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    numberLabel.setPreferredSize(labelSize);

    NumberFormat numberFormat = NumberFormat.getInstance();
    JFormattedTextField numberField = new JFormattedTextField(numberFormat);
    numberField.setColumns(16);//from ww  w  .  j  a v a2 s. c om
    numberField.setFocusLostBehavior(JFormattedTextField.PERSIST);
    numberField.setValue(42);

    JPanel numberPanel = new JPanel();
    numberPanel.add(numberLabel);
    numberPanel.add(new JLayer<JFormattedTextField>(numberField, layerUI));

    // Date field.
    JLabel dateLabel = new JLabel("Date:");
    dateLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    dateLabel.setPreferredSize(labelSize);

    DateFormat dateFormat = DateFormat.getDateInstance();
    JFormattedTextField dateField = new JFormattedTextField(dateFormat);
    dateField.setColumns(16);
    dateField.setFocusLostBehavior(JFormattedTextField.PERSIST);
    dateField.setValue(new java.util.Date());

    JPanel datePanel = new JPanel();
    datePanel.add(dateLabel);
    datePanel.add(new JLayer<JFormattedTextField>(dateField, layerUI));

    // Time field.
    JLabel timeLabel = new JLabel("Time:");
    timeLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    timeLabel.setPreferredSize(labelSize);

    DateFormat timeFormat = DateFormat.getTimeInstance();
    JFormattedTextField timeField = new JFormattedTextField(timeFormat);
    timeField.setColumns(16);
    timeField.setFocusLostBehavior(JFormattedTextField.PERSIST);
    timeField.setValue(new java.util.Date());

    JPanel timePanel = new JPanel();
    timePanel.add(timeLabel);
    timePanel.add(new JLayer<JFormattedTextField>(timeField, layerUI));

    // Put them all in the box.
    box.add(Box.createGlue());
    box.add(numberPanel);
    box.add(Box.createGlue());
    box.add(datePanel);
    box.add(Box.createGlue());
    box.add(timePanel);

    return box;
}

From source file:org.kalypso.model.wspm.pdb.ui.internal.admin.waterbody.imports.WaterLevelLabelProvider.java

@Override
public String getText(final Object element) {
    final Object value = m_property.getValue(element);
    if (value == null)
        return StringUtils.EMPTY;

    if (value instanceof Date) {
        final DateFormat df = DateFormat.getDateInstance();
        return df.format((Date) value);
    }/*  www  . j  a v a 2 s.c om*/

    return String.format(m_format, value);
}

From source file:com.intuit.tank.harness.functions.JexlDateFunctions.java

/**
 * Gets DateFormat based on the string input
 * //  www  .ja va 2s.c o m
 * @param format
 * @return the correct DateFormat
 */
private DateFormat getFormatter(String format) {
    DateFormat formatter = null;
    try {
        formatter = StringUtils.isEmpty(format) ? DateFormat.getDateInstance() : new SimpleDateFormat(format);
    } catch (Exception e) {
        // bad format
        LOG.warn(LogUtil.getLogMessage(
                "Error parsing date format string: " + e.toString() + ". Using default format.",
                LogEventType.System));
        formatter = DateFormat.getDateInstance();
    }
    return formatter;
}

From source file:com.pureinfo.srm.product.action.ProductListAction.java

private Date getBeginYear() {
    Date beginDate = new Date();
    try {//from ww  w .j  ava2s . c  om
        if (request.getParameter("beginDateYear") == null) {
            if (m_nBeginYear <= 0 || m_nBeginYear > RANGE_MAX2) {
                m_nBeginYear = RANGE_BEGIN_YEAR;
            }
        } else {
            m_nBeginYear = Integer.parseInt(request.getParameter("beginDateYear"));
        }
        beginDate = DateFormat.getDateInstance().parse(m_nBeginYear + "-01-01");

    } catch (Exception e) {
        logger.debug("date format error");
    }
    return beginDate;
}

From source file:org.jrb.docasm.ApplicationConfig.java

@Bean
public MappingJackson2HttpMessageConverter messageConverter() {

    // assemble json mapper
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    objectMapper.setDateFormat(DateFormat.getDateInstance());
    objectMapper.configure(Feature.WRITE_NUMBERS_AS_STRINGS, true);

    // assemble json message converter
    final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setObjectMapper(objectMapper);

    return converter;
}

From source file:org.onebusaway.nyc.webapp.actions.admin.VehiclesAction.java

public String getCurrentTimestamp() {
    Date now = new Date();
    return DateFormat.getDateInstance().format(now) + " " + DateFormat.getTimeInstance().format(now);
}

From source file:com.haulmont.chile.core.datatypes.impl.DateTimeDatatype.java

@Override
public Date parse(String value) throws ParseException {
    if (StringUtils.isBlank(value)) {
        return null;
    }//  ww w  .  j av a2 s. c om

    DateFormat format;
    if (formatPattern != null) {
        format = new SimpleDateFormat(formatPattern);
    } else {
        format = DateFormat.getDateInstance();
    }
    return format.parse(value.trim());
}

From source file:org.jamienicol.episodes.AddShowPreviewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.add_show_preview_fragment, container, false);

    TextView overviewView = (TextView) view.findViewById(R.id.overview);
    TextView firstAiredView = (TextView) view.findViewById(R.id.first_aired);

    int searchResultIndex = getArguments().getInt("searchResultIndex");

    AddShowSearchResults results = AddShowSearchResults.getInstance();
    List<Show> resultsData = results.getData();

    // Ensure that there is actually data to display, because Android
    // may have destroyed it. If there is data display it, if there
    // isn't do nothing and the activity will handle the situation.
    if (resultsData != null) {
        show = resultsData.get(searchResultIndex);

        overviewView.setText(show.getOverview());

        Date firstAired = show.getFirstAired();
        if (firstAired != null) {
            DateFormat df = DateFormat.getDateInstance();
            String text = getString(R.string.first_aired, df.format(show.getFirstAired()));
            firstAiredView.setText(text);
        } else {//from w ww  .j a  v  a2  s  . c  o  m
            firstAiredView.setText("");
        }
    }

    return view;
}