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:org.apache.jcs.admin.JCSAdminBean.java

/**
 * Builds up info about each element in a region.
 * <p>//from w  w w  . j ava  2 s . c o  m
 * @param cacheName
 * @return List of CacheElementInfo objects
 * @throws Exception
 */
public LinkedList buildElementInfo(String cacheName) throws Exception {
    CompositeCache cache = cacheHub.getCache(cacheName);

    Object[] keys = cache.getMemoryCache().getKeyArray();

    // Attempt to sort keys according to their natural ordering. If that
    // fails, get the key array again and continue unsorted.

    try {
        Arrays.sort(keys);
    } catch (Exception e) {
        keys = cache.getMemoryCache().getKeyArray();
    }

    LinkedList records = new LinkedList();

    ICacheElement element;
    IElementAttributes attributes;
    CacheElementInfo elementInfo;

    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

    long now = System.currentTimeMillis();

    for (int i = 0; i < keys.length; i++) {
        element = cache.getMemoryCache().getQuiet((Serializable) keys[i]);

        attributes = element.getElementAttributes();

        elementInfo = new CacheElementInfo();

        elementInfo.key = String.valueOf(keys[i]);
        elementInfo.eternal = attributes.getIsEternal();
        elementInfo.maxLifeSeconds = attributes.getMaxLifeSeconds();

        elementInfo.createTime = format.format(new Date(attributes.getCreateTime()));

        elementInfo.expiresInSeconds = (now - attributes.getCreateTime()
                - (attributes.getMaxLifeSeconds() * 1000)) / -1000;

        records.add(elementInfo);
    }

    return records;
}

From source file:codes.thischwa.c5c.requestcycle.response.mode.FileInfoProperties.java

private String getDate(Date date) {
    if (date == null)
        return null;
    Locale locale = RequestData.getLocale();
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    String dateStr = df.format(date);
    return dateStr;
}

From source file:org.ambraproject.annotation.action.GetAnnotationAction.java

/**
 * Returns Milliseconds representation of the CIS start date
 * @return Milliseconds representation of the CIS start date 
 * @throws Exception on bad config data or config entry not found.
 *///from  w w  w .  ja v a 2s .c  o m
public long getCisStartDateMillis() throws Exception {
    try {
        return DateFormat.getDateInstance(DateFormat.SHORT)
                .parse(this.configuration.getString("ambra.platform.cisStartDate")).getTime();
    } catch (ParseException ex) {
        throw (Exception) new Exception(
                "Could not find or parse the cisStartDate node in the ambra platform configuration.  Make sure the ambra/platform/cisStartDate node exists.")
                        .initCause(ex);
    }
}

From source file:org.eclipse.mylyn.internal.reviews.ui.editors.parts.AbstractCommentPart.java

@Override
protected String getSectionHeaderText() {
    IUser author = comment.getAuthor();/* w w w . j a va2s  .co  m*/
    return NLS.bind(Messages.AbstractCommentPart_Section_header, //
            author != null ? author.getDisplayName() : Messages.AbstractCommentPart_No_author, //
            DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT)
                    .format(comment.getCreationDate()) // 
    );
}

From source file:net.sourceforge.processdash.ui.web.reports.XYChart.java

/** Create a scatter plot. */
@Override/*from w  w w .  j a va2 s .c  o m*/
public JFreeChart createChart() {
    JFreeChart chart;
    String xLabel = null, yLabel = null;
    if (!chromeless) {
        xLabel = Translator.translate(data.getColName(1));

        yLabel = getSetting("yLabel");
        if (yLabel == null && data.numCols() == 2)
            yLabel = data.getColName(2);
        if (yLabel == null)
            yLabel = getSetting("units");
        if (yLabel == null)
            yLabel = "Value";
        yLabel = Translator.translate(yLabel);
    }

    Object autoZero = parameters.get("autoZero");

    boolean firstColumnContainsDate = data.numRows() > 0 && data.numCols() > 0
            && data.getData(1, 1) instanceof DateData;
    if (firstColumnContainsDate || parameters.get("xDate") != null) {
        chart = ChartFactory.createTimeSeriesChart(null, xLabel, yLabel, data.xyDataSource(), true, true,
                false);
        if (firstColumnContainsDate && ((DateData) data.getData(1, 1)).isFormatAsDateOnly())
            chart.getXYPlot().getRenderer().setBaseToolTipGenerator(
                    new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                            DateFormat.getDateInstance(DateFormat.SHORT), NumberFormat.getInstance()));
    } else {
        XYDataset src = data.xyDataSource();
        chart = ChartFactory.createScatterPlot(null, xLabel, yLabel, src, PlotOrientation.VERTICAL, true, true,
                false);
        if (src instanceof XYToolTipGenerator) {
            chart.getXYPlot().getRenderer().setBaseToolTipGenerator((XYToolTipGenerator) src);
        }

        String trendLine = getParameter("trend");
        if ("none".equalsIgnoreCase(trendLine))
            ;
        else if ("average".equalsIgnoreCase(trendLine))
            addTrendLine(chart,
                    XYDataSourceTrendLine.getAverageLine(src, 0, autoZero != null && !autoZero.equals("y")));
        else
            addTrendLine(chart,
                    XYDataSourceTrendLine.getRegressionLine(src, 0, autoZero != null && !autoZero.equals("y")));
    }

    if (autoZero != null) {
        if (!"x".equals(autoZero))
            ((NumberAxis) chart.getXYPlot().getRangeAxis()).setAutoRangeIncludesZero(true);
        if (!"y".equals(autoZero))
            ((NumberAxis) chart.getXYPlot().getDomainAxis()).setAutoRangeIncludesZero(true);
    }

    if (data.numCols() == 2)
        chart.removeLegend();

    return chart;
}

From source file:org.ciasaboark.tacere.manager.NotificationManagerWrapper.java

public void displayQuickSilenceNotification(int quicksilenceDurationMinutes) {
    BetaPrefs betaPrefs = new BetaPrefs(context);
    if (betaPrefs.getDisableNotifications()) {
        Log.d(TAG, "asked to display quicksilence notification, but this has been disabled in "
                + "beta settings. Stopping any ongoing notifications");
        cancelAllNotifications();/*from w  w w  . j  a  v a  2  s.  c o m*/
    } else {
        // the intent attached to the notification should only cancel the quick silence request, but
        // not launch the app
        Intent notificationIntent = new Intent(context, EventSilencerService.class);
        notificationIntent.putExtra(EventSilencerService.WAKE_REASON, RequestTypes.CANCEL_QUICKSILENCE.value);
        long endTime = System.currentTimeMillis()
                + (long) quicksilenceDurationMinutes * EventInstance.MILLISECONDS_IN_MINUTE;

        DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
        Date date = new Date(endTime);
        String formattedDate = dateFormat.format(date);
        String formattedString = String
                .format(context.getString(R.string.notification_quicksilence_description), formattedDate);

        // FLAG_CANCEL_CURRENT is required to make sure that the extras are including in the new
        // pending intent
        PendingIntent pendIntent = PendingIntent.getService(context, REQUEST_CODES.QUICKSILENCE_CANCEL,
                notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        //an intent to open the main app
        Intent openMainIntent = new Intent(context, MainActivity.class);
        openMainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        openMainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent openMainPendIntent = PendingIntent.getActivity(context,
                REQUEST_CODES.QUICKSILENCE_OPEN_MAIN, openMainIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        //An additional button to extend the quicksilence by 15min
        // this intent will be attached to the button on the notification
        Intent addMinutesIntent = new Intent(context, ExtendQuicksilenceService.class);
        addMinutesIntent.putExtra(ExtendQuicksilenceService.ORIGINAL_END_TIMESTAMP, endTime);
        addMinutesIntent.putExtra(ExtendQuicksilenceService.EXTEND_LENGTH, 15);
        PendingIntent addMinPendIntent = PendingIntent.getService(context, REQUEST_CODES.QUICKSILENCE_ADD_TIME,
                addMinutesIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(context)
                .setContentTitle(context.getString(R.string.notification_quicksilence_title))
                .setContentText(formattedString)
                .setTicker(context.getString(R.string.notification_quicksilence_ticker))
                .setSmallIcon(R.drawable.not_silence).setAutoCancel(true).setOngoing(true)
                .setContentIntent(pendIntent).setColor(context.getResources().getColor(R.color.accent))
                .setTicker(context.getString(R.string.notification_quicksilence_ticker));

        notBuilder.addAction(R.drawable.app_mono_small, "Open Tacere", openMainPendIntent);
        //the +15 button should only be available in the Pro version
        Authenticator authenticator = new Authenticator(context);
        if (authenticator.isAuthenticated()) {
            notBuilder.addAction(R.drawable.not_clock, "+15", addMinPendIntent);
        }

        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        nm.cancel(NOTIFICATION_ID);
        nm.notify(NOTIFICATION_ID, notBuilder.build());
    }
}

From source file:org.springframework.binding.convert.converters.StringToDate.java

protected DateFormat getDateFormat() {
    Locale locale = determineLocale(this.locale);
    DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    format.setLenient(false);//w w  w  . ja v  a 2s  .co m
    if (format instanceof SimpleDateFormat) {
        String pattern = determinePattern(this.pattern);
        ((SimpleDateFormat) format).applyPattern(pattern);
    } else {
        logger.warn("Unable to apply format pattern '" + pattern
                + "'; Returned DateFormat is not a SimpleDateFormat");
    }
    return format;
}

From source file:org.rhq.modules.plugins.wildfly10.util.PatchDetails.java

private static PatchDetails processJSONParseResult(Map<String, String> jsonParseResult) {
    String patchId = jsonParseResult.get("patch-id");
    Date appliedAt = null;//from   www  . j  a  va2  s .com
    Type type = Type.fromJsonValue(jsonParseResult.get("type"));

    try {
        //This seems to be the date format AS are using
        DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

        appliedAt = format.parse(jsonParseResult.get("applied-at"));
    } catch (ParseException e) {
        LOG.info("Failed to parse the installation date of the patch " + patchId + ": '"
                + jsonParseResult.get("applied-at") + "' with error message: " + e.getMessage());
    }

    return new PatchDetails(patchId, type, appliedAt);
}

From source file:com.microsoft.tfs.client.common.ui.controls.vc.LabelItemTable.java

@Override
protected String getColumnText(final Object element, final String propertyName) {
    final LabelItem item = (LabelItem) element;

    if (propertyName.equals(ITEM_COLUMN_ID)) {
        return VersionedFileSpec.formatPathWithDeletionIfNecessary(item.getServerItem(), item.getDeletionID());
    } else if (propertyName.equals(VERSION_COLUMN_ID)) {
        final VersionSpec versionSpec = item.getVersionSpec();

        if (versionSpec instanceof LatestVersionSpec) {
            return Messages.getString("LabelItemTable.ColumnTextLatest"); //$NON-NLS-1$
        } else if (versionSpec instanceof LabelVersionSpec) {
            final LabelVersionSpec labelSpec = (LabelVersionSpec) versionSpec;

            return labelSpec.getLabel() + "@" + labelSpec.getScope(); //$NON-NLS-1$
        } else if (versionSpec instanceof DateVersionSpec) {
            final Date date = ((DateVersionSpec) versionSpec).getDate().getTime();
            return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date);
        } else if (versionSpec instanceof WorkspaceVersionSpec) {
            final WorkspaceVersionSpec workspaceSpec = (WorkspaceVersionSpec) versionSpec;

            return workspaceSpec.getName() + ";" + workspaceSpec.getOwner(); //$NON-NLS-1$
        } else if (versionSpec instanceof ChangesetVersionSpec) {
            return Integer.toString(((ChangesetVersionSpec) versionSpec).getChangeset());
        } else {/*from  w  w w  .  j a v  a2  s.c o  m*/
            return versionSpec.toString();
        }
    }

    return "(Unknown)"; //$NON-NLS-1$
}

From source file:org.codekaizen.vtj.text.BpDateFormatTest.java

/**
 * DOCUMENT ME!/*from  ww w  .j  av  a  2 s  .  c  om*/
 */
public void testFormatting() {
    DateFormat fmt1 = null;
    DateFormat fmt2 = null;
    Date date = null;
    String s1 = null;
    String s2 = null;

    date = new Date();

    fmt1 = new BpDateFormat(BpDateFormat.JVM_DATE_TIME, null);
    fmt2 = DateFormat.getDateTimeInstance();
    s1 = fmt1.format(date);
    s2 = fmt2.format(date);
    assertEquals(s2, s1);

    fmt1 = new BpDateFormat(BpDateFormat.JVM_DATE_ONLY, null);
    fmt2 = DateFormat.getDateInstance(DateFormat.SHORT);
    s1 = fmt1.format(date);
    s2 = fmt2.format(date);
    assertEquals(s2, s1);

    fmt1 = new BpDateFormat(BpDateFormat.JVM_TIME_ONLY, null);
    fmt2 = DateFormat.getTimeInstance(DateFormat.SHORT);
    s1 = fmt1.format(date);
    s2 = fmt2.format(date);
    assertEquals(s2, s1);

    fmt1 = new BpDateFormat(BpDateFormat.JVM_FULL_DATE, null);
    fmt2 = DateFormat.getDateInstance(DateFormat.FULL);
    s1 = fmt1.format(date);
    s2 = fmt2.format(date);
    assertEquals(s2, s1);

    fmt1 = new BpDateFormat(BpDateFormat.JVM_DATE_TIME, Locale.CANADA_FRENCH);
    fmt2 = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.CANADA_FRENCH);
    s1 = fmt1.format(date);
    s2 = fmt2.format(date);
    assertEquals(s2, s1);

}