Example usage for java.text DateFormat SHORT

List of usage examples for java.text DateFormat SHORT

Introduction

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

Prototype

int SHORT

To view the source code for java.text DateFormat SHORT.

Click Source Link

Document

Constant for short style pattern.

Usage

From source file:de.aw.awlib.preferences.AWPreferencesAllgemein.java

@CallSuper
@Override//from ww w .  j  a va 2s.c  om
public void onCreatePreferences(Bundle bundle, String s) {
    mApplication = ((AWApplication) getActivity().getApplicationContext());
    addPreferencesFromResource(R.xml.awlib_preferences_allgemein);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    for (int pkKey : mPrefs) {
        String key = getString(pkKey);
        Preference preference = findPreference(key);
        if (pkKey == R.string.pkCompileInfo) {
            java.util.Date date = new Date(BuildConfig.BuildTime);
            DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
            StringBuilder buildInfo = new StringBuilder("Compilezeit: ").append(df.format(date));
            preference.setSummary(buildInfo);
        } else if (pkKey == R.string.pkVersionInfo) {
            StringBuilder versionInfo = new StringBuilder("Datenbankversion : ")
                    .append(mApplication.theDatenbankVersion()).append(", Version: ")
                    .append(BuildConfig.VERSION_NAME);
            preference.setSummary(versionInfo);
        } else if (pkKey == R.string.pkServerUID || pkKey == R.string.pkServerURL) {
            String value = prefs.getString(key, null);
            preference.setSummary(value);
        } else if (pkKey == R.string.pkSavePeriodic) {
            long value = prefs.getLong(DODATABASESAVE, Long.MAX_VALUE);
            setRegelmSicherungSummary(preference, prefs, value);
        }
        preference.setOnPreferenceClickListener(this);
    }
}

From source file:org.kuali.coeus.common.questionnaire.framework.answer.SaveQuestionnaireAnswerRule.java

private boolean validateAttributeFormat(Answer answer, String errorKey, int questionIndex) {
    boolean valid = true;

    ValidationPattern validationPattern = VALIDATION_CLASSES
            .get(answer.getQuestion().getQuestionTypeId().toString());

    // if there is no data type matched, then set error ?
    Pattern validationExpression = validationPattern.getRegexPattern();

    String validFormat = getValidFormat(answer.getQuestion().getQuestionTypeId().toString());

    if (validFormat.equals(Constants.DATA_TYPE_STRING) || validFormat.equals(Constants.DATA_TYPE_NUMBER)) {
        if (!validationExpression.matcher(answer.getAnswer()).matches()) {
            GlobalVariables.getMessageMap().putError(errorKey, KeyConstants.ERROR_INVALID_FORMAT_WITH_FORMAT,
                    new String[] { ANSWER + (questionIndex + 1), answer.getAnswer(), validFormat });
            valid = false;/*from  w  w  w  . j ava2 s .  c  om*/
        }
    } else if (validFormat.equals(Constants.DATA_TYPE_DATE)) {
        try {
            DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
            dateFormat.setLenient(false);
            dateFormat.parse(answer.getAnswer());
        } catch (ParseException e) {
            GlobalVariables.getMessageMap().putError(errorKey, RiceKeyConstants.ERROR_INVALID_FORMAT,
                    ANSWER + (questionIndex + 1), answer.getAnswer(), validFormat);
            valid = false;
        }
    }

    return valid;
}

From source file:io.wcm.devops.conga.generator.FileGenerator.java

/**
 * Generate comment lines for file header added to all files for which a {@link FileHeaderPlugin} is registered.
 * @param dependencyVersions List of artifact versions to include
 * @return Formatted comment lines//from  w  ww  .j  a  v  a 2 s. co m
 */
private List<String> buildFileHeaderCommentLines(String version, List<String> dependencyVersions) {
    List<String> lines = new ArrayList<>();

    lines.add("This file is AUTO-GENERATED by CONGA. Please do no change it manually.");
    lines.add("");
    lines.add((version != null ? "Version " + version + ", generated " : "Generated ") + "at: "
            + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(new Date()));

    // add information how this file was generated
    lines.add("Environment: " + environmentName);
    lines.add("Role: " + roleName);
    if (StringUtils.isNotBlank(roleVariantName)) {
        lines.add("Variant: " + roleVariantName);
    }
    lines.add("Template: " + templateName);

    if (dependencyVersions != null && !dependencyVersions.isEmpty()) {
        lines.add("");
        lines.add("Dependencies:");
        lines.addAll(dependencyVersions);
    }

    return formatFileHeaderCommentLines(lines);
}

From source file:org.hawkular.client.android.fragment.MetricFragment.java

private void setUpMetricData(List<MetricData> metricDataList) {
    this.metricData = new ArrayList<>(metricDataList);

    sortMetricData(metricDataList);/*from   w ww. jav a 2 s  .c o  m*/

    List<PointValue> chartPoints = new ArrayList<>();

    List<AxisValue> chartAxisPoints = new ArrayList<>();

    for (int metricDataPosition = 0; metricDataPosition < metricDataList.size(); metricDataPosition++) {
        MetricData metricData = metricDataList.get(metricDataPosition);

        chartPoints.add(new PointValue(metricDataPosition, metricData.getValue()));

        chartAxisPoints.add(new AxisValue(metricDataPosition).setLabel(
                DateFormat.getTimeInstance(DateFormat.SHORT).format(new Date(metricData.getTimestamp()))));
    }

    Line chartLine = new Line(chartPoints).setColor(getResources().getColor(R.color.background_primary_dark))
            .setCubic(true).setHasPoints(false);

    LineChartData chartData = new LineChartData().setLines(Collections.singletonList(chartLine));
    chartData.setAxisXBottom(new Axis().setValues(chartAxisPoints));
    chartData.setAxisYLeft(new Axis().setHasLines(true));

    chart.setLineChartData(chartData);

    Viewport chartViewport = new Viewport(chart.getMaximumViewport());

    chartViewport.bottom = chart.getMaximumViewport().bottom - 50;
    chartViewport.top = chart.getMaximumViewport().top + 50;

    chart.setMaximumViewport(chartViewport);
    chart.setCurrentViewport(chartViewport);

    hideRefreshing();

    showChart();
}

From source file:com.facultyshowcase.app.ui.UIUtil.java

public static void writeProperty(EntityUtilWriter writer, String htmlClass, String label, Date date) {
    final DateFormat parser = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

    writeContainerBeginning(writer, htmlClass);

    writeLabel(writer, htmlClass, label);

    writer.append("<span ");
    writer.appendEscapedAttribute(CLASS, CmsHTMLClassNames.convertClassName(PROP + " " + htmlClass));
    writer.append(">");
    writer.appendEscapedData(date != null ? parser.format(date) : StringUtils.EMPTY);
    writer.append("</span>");

    writeContainerEnd(writer);/*from   w  ww  . j  av  a  2s.  co  m*/
}

From source file:org.springsource.ide.eclipse.dashboard.internal.ui.editors.FeedsLabelProvider.java

public String getColumnText(Object element, int index) {
    // // TODO Auto-generated method stub
    // return super.getText(element);
    // }/*  w w  w  . j  a v a  2  s.co  m*/
    // public String getColumnText(Object element, int columnIndex) {
    if (element instanceof StubSyndEntryImpl) {
        return removeHtmlEntities(((StubSyndEntryImpl) element).getText());
    }
    if (element instanceof SyndEntry) {
        SyndEntry entry = (SyndEntry) element;
        SyndFeed feed = feedsMap.get(entry);
        if (feed == null) {
            return null;
        }

        String title = entry.getTitle();

        Date entryDate = new Date(0);
        if (entry.getUpdatedDate() != null) {
            entryDate = entry.getUpdatedDate();
        } else {
            entryDate = entry.getPublishedDate();
        }

        String dateString = "";
        if (entryDate != null) {
            dateString = DateFormat.getDateInstance(DateFormat.SHORT).format(entryDate);
        }

        String entryAuthor = "";
        if (entry.getAuthor() != null && entry.getAuthor().trim() != "") {
            entryAuthor = " by " + entry.getAuthor();
        }

        if (feedType.equals(DashboardMainPage.FeedType.BLOG) && dateString.length() > 0
                && entryAuthor.length() > 0) {
            return removeHtmlEntities(title + " (" + dateString + entryAuthor + ")");
        }
        return removeHtmlEntities(title);
    }

    return null;
}

From source file:edu.ku.brc.specify.prefs.FormattingPrefsPanel.java

/**
 * /*from   ww w. ja v  a  2 s  .c  o  m*/
 */
protected void fillDateFormat() {

    String currentFormat = AppPreferences.getRemote().get("ui.formatting.scrdateformat", null);

    TimeZone tz = TimeZone.getDefault();
    DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
    dateFormatter.setTimeZone(tz);
    String dateStr = dateFormatter.format(Calendar.getInstance().getTime());
    Character ch = null;
    for (int i = 0; i < 10; i++) {
        if (!StringUtils.isNumeric(dateStr.substring(i, i + 1))) {
            ch = dateStr.charAt(i);
            break;
        }
    }

    if (ch != null) {
        boolean skip = false;
        Vector<String> formats = new Vector<String>();
        if (ch == '/') {
            addFormats(formats, '/');
            skip = true;
        }
        if (ch != '.') {
            addFormats(formats, '.');
            skip = true;
        }
        if (ch != '-') {
            addFormats(formats, '-');
            skip = true;
        }

        if (!skip) {
            addFormats(formats, ch);
        }

        int selectedInx = 0;
        int inx = 0;
        DefaultComboBoxModel model = (DefaultComboBoxModel) dateFieldCBX.getModel();
        for (String fmt : formats) {
            model.addElement(fmt);
            if (currentFormat != null && currentFormat.equals(fmt)) {
                selectedInx = inx;
            }
            inx++;
        }
        dateFieldCBX.getComboBox().setSelectedIndex(selectedInx);
    }
}

From source file:org.opencms.scheduler.jobs.CmsPublishJob.java

/**
 * @see org.opencms.scheduler.I_CmsScheduledJob#launch(org.opencms.file.CmsObject, java.util.Map)
 *///from www .  j  a  v a2 s. c o m
public synchronized String launch(CmsObject cms, Map<String, String> parameters) throws Exception {

    Date jobStart = new Date();
    String finishMessage;
    String unlock = parameters.get(PARAM_UNLOCK);
    String linkcheck = parameters.get(PARAM_LINKCHECK);
    CmsProject project = cms.getRequestContext().getCurrentProject();

    CmsLogReport report = new CmsLogReport(cms.getRequestContext().getLocale(), CmsPublishJob.class);

    try {

        // check if the unlock parameter was given
        if (Boolean.valueOf(unlock).booleanValue()) {
            cms.unlockProject(project.getUuid());
        }

        // validate links if linkcheck parameter was given
        if (Boolean.valueOf(linkcheck).booleanValue()) {
            OpenCms.getPublishManager().validateRelations(cms, OpenCms.getPublishManager().getPublishList(cms),
                    report);
        }

        // publish the project, the publish output will be put in the logfile
        OpenCms.getPublishManager().publishProject(cms, report);
        OpenCms.getPublishManager().waitWhileRunning();
        finishMessage = Messages.get().getBundle().key(Messages.LOG_PUBLISH_FINISHED_1, project.getName());
    } catch (CmsException e) {
        // there was an error, so create an output for the logfile
        finishMessage = Messages.get().getBundle().key(Messages.LOG_PUBLISH_FAILED_2, project.getName(),
                e.getMessageContainer().key());

        // add error to report
        report.addError(finishMessage);
    } finally {
        //wait for other processes that may add entries to the report
        long lastTime = report.getLastEntryTime();
        long beforeLastTime = 0;
        while (lastTime != beforeLastTime) {
            wait(300000);
            beforeLastTime = lastTime;
            lastTime = report.getLastEntryTime();
        }

        // send publish notification
        if (report.hasWarning() || report.hasError()) {
            try {
                String userName = parameters.get(PARAM_USER);
                CmsUser user = cms.readUser(userName);

                CmsPublishNotification notification = new CmsPublishNotification(cms, user, report);

                DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
                notification.addMacro("jobStart", df.format(jobStart));

                notification.send();
            } catch (Exception e) {
                LOG.error(Messages.get().getBundle().key(Messages.LOG_PUBLISH_SEND_NOTIFICATION_FAILED_0), e);
            }
        }
    }

    return finishMessage;
}

From source file:org.mifos.framework.util.helpers.DateUtils.java

public static String getUserLocaleDate(String databaseDate) {
    if (internalLocale != null && databaseDate != null && !databaseDate.equals("")) {
        try {/*from  ww  w  .ja v  a  2s. co  m*/
            SimpleDateFormat shortFormat = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT,
                    internalLocale);
            String userfmt = convertToCurrentDateFormat(shortFormat.toPattern());
            return convertDbToUserFmt(databaseDate, userfmt);
        } catch (FrameworkRuntimeException e) {
            throw e;
        } catch (Exception e) {
            System.out.println("databaseDate=" + databaseDate + ", locale=" + internalLocale);
            throw new FrameworkRuntimeException(e);
        }
    } else {
        return "";
    }
}

From source file:com.jgoodies.validation.tutorial.formatted.DateExample.java

/**
 * Appends the demo rows to the given builder and returns the List of
 * formatted text fields.//from   ww  w .  j a  v a  2 s  . co  m
 * 
 * @param builder  the builder used to add components to
 * @return the List of formatted text fields
 */
private List appendDemoRows(DefaultFormBuilder builder) {
    // The Formatter is choosen by the initial value.
    JFormattedTextField defaultDateField = new JFormattedTextField(new Date());

    // The Formatter is choosen by the given Format.
    JFormattedTextField noInitialValueField = new JFormattedTextField(DateFormat.getDateInstance());

    // Uses a custom DateFormat.
    DateFormat customFormat = DateFormat.getDateInstance(DateFormat.SHORT);
    JFormattedTextField customFormatField = new JFormattedTextField(new DateFormatter(customFormat));

    // Uses a RelativeDateFormat.
    DateFormat relativeFormat = new RelativeDateFormat();
    JFormattedTextField relativeFormatField = new JFormattedTextField(new DateFormatter(relativeFormat));

    // Uses a custom DateFormatter that allows relative input and
    // prints natural language strings.
    JFormattedTextField relativeFormatterField = new JFormattedTextField(new RelativeDateFormatter());

    // Uses a custom FormatterFactory that used different formatters
    // for the display and while editing.
    DefaultFormatterFactory formatterFactory = new DefaultFormatterFactory(
            new RelativeDateFormatter(false, true), new RelativeDateFormatter(true, true));
    JFormattedTextField relativeFactoryField = new JFormattedTextField(formatterFactory);

    // Wraps a DateFormatter to map empty strings to null and vice versa.
    JFormattedTextField numberOrNullField = new JFormattedTextField(new EmptyDateFormatter());

    // Wraps a DateFormatter to map empty strings to -1 and vice versa.
    Date epoch = new Date(0); // January 1, 1970
    JFormattedTextField numberOrEmptyValueField = new JFormattedTextField(new EmptyDateFormatter(epoch));
    numberOrEmptyValueField.setValue(epoch);

    // Commits value on valid edit text
    DefaultFormatter formatter = new RelativeDateFormatter();
    formatter.setCommitsOnValidEdit(true);
    JFormattedTextField commitOnValidEditField = new JFormattedTextField(formatter);

    // A date field as created by the BasicComponentFactory:
    // Uses relative date input, and maps empty strings to null.
    ValueModel dateHolder = new ValueHolder();
    JFormattedTextField componentFactoryField = ExampleComponentFactory.createDateField(dateHolder);

    Format displayFormat = new DisplayFormat(DateFormat.getDateInstance());
    List fields = new LinkedList();
    fields.add(Utils.appendRow(builder, "Default", defaultDateField, displayFormat));
    fields.add(Utils.appendRow(builder, "No initial value", noInitialValueField, displayFormat));
    fields.add(Utils.appendRow(builder, "Empty <->  null", numberOrNullField, displayFormat));
    fields.add(Utils.appendRow(builder, "Empty <-> epoch", numberOrEmptyValueField, displayFormat));
    fields.add(Utils.appendRow(builder, "Short format", customFormatField, displayFormat));
    fields.add(Utils.appendRow(builder, "Relative format", relativeFormatField, displayFormat));
    fields.add(Utils.appendRow(builder, "Relative formatter", relativeFormatterField, displayFormat));
    fields.add(Utils.appendRow(builder, "Relative factory", relativeFactoryField, displayFormat));
    fields.add(Utils.appendRow(builder, "Commits on valid edit", commitOnValidEditField, displayFormat));
    fields.add(Utils.appendRow(builder, "Relative, maps null", componentFactoryField, displayFormat));

    return fields;
}