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.rhq.modules.plugins.wildfly10.util.PatchDetails.java

@Override
public String toString() {
    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

    return "{\n  \"patch-id\": \"" + id + "\",\n  \"type\": \"" + type + "\",\n  \"applied-at\": \""
            + format.format(appliedAt) + "\"\n}";
}

From source file:org.svij.taskwarriorapp.activities.TaskAddActivity.java

public void onCreate(Bundle savedInstanceState) {
    setTheme(android.R.style.Theme_Holo_Light_DarkActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_task_add);

    final TextView tvDueDate = (TextView) findViewById(R.id.tvDueDate);
    tvDueDate.setOnClickListener(new View.OnClickListener() {

        @Override/*from   w ww . jav  a  2 s  .c  om*/
        public void onClick(View v) {
            FragmentManager fm = getSupportFragmentManager();
            CalendarDatePickerDialog calendarDatePickerDialog = CalendarDatePickerDialog.newInstance(
                    TaskAddActivity.this, Calendar.getInstance().get(Calendar.YEAR),
                    Calendar.getInstance().get(Calendar.MONTH),
                    Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
            calendarDatePickerDialog.show(fm, "fragment_date_picker");
        }
    });

    final TextView tvDueTime = (TextView) findViewById(R.id.tvDueTime);
    tvDueTime.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            FragmentManager fm = getSupportFragmentManager();
            RadialTimePickerDialog timePickerDialog = RadialTimePickerDialog.newInstance(TaskAddActivity.this,
                    Calendar.getInstance().get(Calendar.HOUR_OF_DAY),
                    Calendar.getInstance().get(Calendar.MINUTE),
                    android.text.format.DateFormat.is24HourFormat(TaskAddActivity.this));
            timePickerDialog.show(fm, "fragment_time_picker_name");
        }
    });

    tvDueDate.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (TextUtils.isEmpty(tvDueTime.getText().toString())) {
                timestamp = 0;
            } else {
                cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
                cal.set(Calendar.MONTH, Calendar.getInstance().get(Calendar.MONTH));
                cal.set(Calendar.DAY_OF_MONTH, Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
                timestamp = cal.getTimeInMillis();
            }
            tvDueDate.setText("");
            return true;
        }
    });

    tvDueTime.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (TextUtils.isEmpty(tvDueDate.getText().toString())) {
                timestamp = 0;
            } else {
                cal.set(Calendar.HOUR_OF_DAY, 0);
                cal.set(Calendar.MINUTE, 0);
                cal.set(Calendar.SECOND, 0);
                timestamp = cal.getTimeInMillis();
            }
            tvDueTime.setText("");
            return true;
        }
    });

    TaskDatabase dataSource = new TaskDatabase(this);
    ArrayList<String> projects = dataSource.getProjects();
    projects.removeAll(Collections.singleton(null));
    final AutoCompleteTextView actvProject = (AutoCompleteTextView) findViewById(R.id.actvProject);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            projects.toArray(new String[projects.size()]));
    actvProject.setAdapter(adapter);
    actvProject.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            actvProject.showDropDown();
            return false;
        }
    });

    Intent intent = getIntent();
    Bundle extras = intent.getExtras();

    if (extras != null) {
        taskID = extras.getString("taskID");

        if (taskID != null) {
            data = new TaskDatabase(this);
            Task task = data.getTask(UUID.fromString(taskID));

            TextView etTaskAdd = (TextView) findViewById(R.id.etTaskAdd);
            Spinner spPriority = (Spinner) findViewById(R.id.spPriority);

            etTaskAdd.setText(task.getDescription());
            if (task.getDue() != null && task.getDue().getTime() != 0) {

                tvDueDate.setText(DateFormat.getDateInstance(DateFormat.SHORT).format(task.getDue()));
                if (!DateFormat.getTimeInstance().format(task.getDue()).equals("00:00:00")) {
                    tvDueTime.setText(DateFormat.getTimeInstance(DateFormat.SHORT).format(task.getDue()));
                }

                cal.setTime(task.getDue());
                timestamp = cal.getTimeInMillis();

            }
            actvProject.setText(task.getProject());

            Log.i("PriorityID", ":" + task.getPriorityID());
            spPriority.setSelection(task.getPriorityID());

            if (task.getTags() != null) {
                TextView etTags = (TextView) findViewById(R.id.etTags);
                String tagString = "";

                for (String s : task.getTags()) {
                    tagString += s + " ";
                }
                etTags.setText(tagString.trim());
            }
        } else {
            String action = intent.getAction();
            if ((action.equalsIgnoreCase(Intent.ACTION_SEND)
                    || action.equalsIgnoreCase("com.google.android.gm.action.AUTO_SEND"))
                    && intent.hasExtra(Intent.EXTRA_TEXT)) {
                String s = intent.getStringExtra(Intent.EXTRA_TEXT);
                TextView etTaskAdd = (TextView) findViewById(R.id.etTaskAdd);
                etTaskAdd.setText(s);
                addingTaskFromOtherApp = true;
            }
        }
    }

}

From source file:ubic.gemma.analysis.preprocess.batcheffects.BatchInfoPopulationHelperServiceImpl.java

/**
 * Apply some heuristics to condense the dates down to batches. For example, we might assume dates very close
 * together (for example, in the same day or within MAX_GAP_BETWEEN_SAMPLES_TO_BE_SAME_BATCH, and we avoid singleton
 * batches) are to be treated as the same batch (see implementation for details).
 * /*from w w w  .j  a v  a2s.co m*/
 * @param allDates
 * @return
 */
protected Map<String, Collection<Date>> convertDatesToBatches(Collection<Date> allDates) {
    List<Date> lDates = new ArrayList<Date>(allDates);
    Collections.sort(lDates);
    Map<String, Collection<Date>> result = new LinkedHashMap<String, Collection<Date>>();

    int batchNum = 1;
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
    String batchDateString = "";

    boolean mergedAnySingletons = false;

    /*
     * Iterate over dates
     */
    Date lastDate = null;
    Date nextDate = null;
    for (int i = 0; i < lDates.size(); i++) {
        Date currentDate = lDates.get(i);

        if (i < lDates.size() - 1) {
            nextDate = lDates.get(i + 1);
        } else {
            nextDate = null;
        }

        if (lastDate == null) {
            // Start our first batch.
            batchDateString = formatBatchName(batchNum, df, currentDate);
            result.put(batchDateString, new HashSet<Date>());
            result.get(batchDateString).add(currentDate);
            lastDate = currentDate;
            continue;
        }

        /*
         * Decide whether we have entered a new batch.
         * 
         * Rules:
         * 
         * - Processing on the same day is always considered the same batch.
         * 
         * - Gaps of less then MAX_GAP_BETWEEN_SAMPLES_TO_BE_SAME_BATCH hours are considered the same batch even if
         * the day is different. Allows for "overnight running" of batches.
         * 
         * And then two rules that keep us from having batches with just one sample. Such batches buy us nothing at
         * all.
         * 
         * - A "singleton" batch at the end of the series is always combined with the last batch.
         * 
         * - A "singleton" batch in the middle is combined with either the next or previous batch, whichever is
         * nearer in time.
         */
        if (gapIsLarge(lastDate, currentDate) && result.get(batchDateString).size() > 1) {

            if (nextDate == null) {
                /*
                 * We're at the last sample, and it's a singleton. We fall through and allow adding it to the end of
                 * the last batch.
                 */
                log.warn("Singleton at the end of the series, combining with the last batch: gap is "
                        + String.format("%.2f",
                                (currentDate.getTime() - lastDate.getTime()) / (double) (1000 * 60 * 60 * 24))
                        + " hours.");
                mergedAnySingletons = true;
            } else if (gapIsLarge(currentDate, nextDate)) {
                /*
                 * Then we have a singleton that will be stranded when we go to the next date. Do we combine it
                 * forwards or backwards? We choose the smaller gap.
                 */
                long backwards = currentDate.getTime() - lastDate.getTime();
                long forwards = nextDate.getTime() - currentDate.getTime();

                if (forwards < backwards) {
                    // Start a new batch.
                    log.warn("Singleton resolved by waiting for the next batch: gap is " + String.format("%.2f",
                            (nextDate.getTime() - currentDate.getTime()) / (double) (1000 * 60 * 60 * 24))
                            + " hours.");
                    batchNum++;
                    batchDateString = formatBatchName(batchNum, df, currentDate);
                    result.put(batchDateString, new HashSet<Date>());
                    mergedAnySingletons = true;
                } else {
                    log.warn("Singleton resolved by adding to the last batch: gap is " + String.format("%.2f",
                            (currentDate.getTime() - lastDate.getTime()) / (double) (1000 * 60 * 60 * 24))
                            + " hours.");
                    // don't start a new batch, fall through.
                }

            } else {
                batchNum++;
                batchDateString = formatBatchName(batchNum, df, currentDate);
                result.put(batchDateString, new HashSet<Date>());
            }

        }
        // else we fall through and add the current date to the current batch.

        // express the constraint that we don't allow batches of size 1, even if we would have normally left it in
        // its own batch.
        if (result.get(batchDateString).size() == 1 && gapIsLarge(lastDate, currentDate)) {
            mergedAnySingletons = true;
            log.warn("Stranded singleton automatically being merged into a larger batch");
        }

        result.get(batchDateString).add(currentDate);
        lastDate = currentDate;
    }

    if (mergedAnySingletons && result.size() == 1) {
        // The implication is that if we didn't have the singleton merging, we would have more than one batch.
        log.warn("Singleton merging resulted in all batches being combined");
    }

    return result;

}

From source file:com.itude.mobile.mobbl.core.util.StringUtilities.java

public static String formatDateDependingOnCurrentDate(String dateString) {
    if (isEmpty(dateString)) {
        return "";
    }/*from ww w .j a  v a 2  s.c om*/

    String result = dateString;
    Date date = dateFromXML(dateString);

    DateFormat df;
    // We can't just compare two dates, because the time is also compared.
    // Therefore the time is removed and the two dates without time are compared
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);

    Calendar today = Calendar.getInstance();
    today.setTime(new Date());

    if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR)
            && calendar.get(Calendar.MONTH) == today.get(Calendar.MONTH)
            && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) {
        df = new SimpleDateFormat("HH:mm:ss");

    } else {
        df = DateFormat.getDateInstance(DateFormat.SHORT,
                getDefaultFormattingLocale() != null ? getDefaultFormattingLocale() : Locale.getDefault());
    }

    // Format the date
    try {
        result = df.format(date);
        return result;
    } catch (Exception e) {
        throw new MBDateParsingException(
                "Could not get format date depending on current date with input string: " + dateString, e);
    }

}

From source file:com.androidquery.simplefeed.activity.PlaceActivity.java

@Override
protected String makeTitle(long time) {
    String result = getString(R.string.n_locations);
    if (time > 0) {
        result += " - " + DateUtils.formatSameDayTime(time, System.currentTimeMillis(), DateFormat.SHORT,
                DateFormat.SHORT);
    }/*from  ww w .  j a  v  a2s . com*/
    return result;
}

From source file:org.helianto.core.domain.IdentitySecurity.java

public String getLastModifiedTimeAsString() {
    if (getLastModified() == null) {
        return "";
    }/*from www  .  j  av  a2 s. c o m*/
    DateFormat formatter = SimpleDateFormat.getTimeInstance(DateFormat.SHORT);
    return formatter.format(getLastModified());
}

From source file:com.adamkruger.myipaddressinfo.IPAddressInfoFragment.java

private void updateViewState() {
    View view = getView();//  w w  w .j av a2 s .co m
    if (view != null) {
        ((TextView) view.findViewById(R.id.ipValue)).setText(mIPAddress);
        ((TextView) view.findViewById(R.id.ispValue)).setText(mISP);
        ((TextView) view.findViewById(R.id.countryValue)).setText(mCountry);
        ((TextView) view.findViewById(R.id.cityValue)).setText(mCity);
        ((TextView) view.findViewById(R.id.regionValue)).setText(mRegion);
        ((TextView) view.findViewById(R.id.coordinatesValue)).setText(mLatLong.length() == 0 ? ""
                : Html.fromHtml(
                        String.format("<a href=\"%s\">%s</a>", mapLink(mLatLong, mIPAddress), mLatLong)));

        if (mLastUpdateTime != null) {
            TextView lastUpdateStatus = (TextView) view.findViewById(R.id.lastUpdateStatus);
            if (mLastUpdateTimedOut) {
                lastUpdateStatus
                        .setText(String.format(getResources().getString(R.string.last_update_status_timeout),
                                mLastUpdateElapsedTimeMs / 1000));
                lastUpdateStatus.setTextColor(getResources().getColor(R.color.error_color));
            } else if (mLastUpdateSucceeded) {
                lastUpdateStatus
                        .setText(String.format(getResources().getString(R.string.last_update_status_success),
                                mLastUpdateElapsedTimeMs));
                if (mLastUpdateElapsedTimeMs < 2000) {
                    lastUpdateStatus.setTextColor(getResources().getColor(R.color.success_color));
                } else {
                    lastUpdateStatus.setTextColor(getResources().getColor(R.color.warning_color));
                }
            } else {
                lastUpdateStatus.setText(String.format(
                        getResources().getString(R.string.last_update_status_fail), mLastUpdateElapsedTimeMs));
                lastUpdateStatus.setTextColor(getResources().getColor(R.color.error_color));
            }

            TextView lastUpdateTime = (TextView) view.findViewById(R.id.lastUpdateTime);
            lastUpdateTime.setText(
                    String.format(getResources().getString(R.string.last_update_time), mLastUpdateTime));
            String currentTime = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault())
                    .format(new Date());
            if (currentTime.equals(mLastUpdateTime)) {
                lastUpdateTime.setTextColor(mDefaultLastUpdateTimeColor);
            } else {
                lastUpdateTime.setTextColor(getResources().getColor(R.color.warning_color));
            }
        }
    }
}

From source file:eu.e43.impeller.Utils.java

public static String humanDate(long milis) {
    return DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(new Date(milis))
            .replace(' ', '\u00A0');
}

From source file:hornet.framework.export.fdf.FDF.java

/**
 * Fusion d'un champ FDF.// w ww. j  a  va  2 s.  c  om
 *
 * @param data
 *            the data
 * @param stamper
 *            the stamper
 * @param res
 *            the res
 * @param form
 *            the form
 * @param nomField
 *            the nom field
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws DocumentException
 *             the document exception
 */
private static void fusionChamp(final Object data, final PdfStamper stamper, final FDFRes res,
        final AcroFields form, final Object nomField) throws IOException, DocumentException {

    // utilisation du ":" comme sparateur d'accs.
    // le "." tant remplac par "_" par openoffice lors
    // de la conversion PDF.
    final String nomFieldStr = nomField.toString().replace(':', '.');

    Object value = null;
    try {
        value = PropertyUtils.getProperty(data, nomFieldStr);
    } catch (final Exception ex) {
        res.getUnmerged().add(nomFieldStr);
    }

    String valueStr;

    if (value == null) {
        valueStr = ""; // itext n'accepte pas les valeurs
        // nulles
        form.setField(nomField.toString(), valueStr);
    } else if (value instanceof FDFImage) {
        final FDFImage imValue = (FDFImage) value;
        final float[] positions = form.getFieldPositions(nomField.toString());
        final PdfContentByte content = stamper.getOverContent(1);
        final Image im = Image.getInstance(imValue.getData());
        if (imValue.isFit()) {
            content.addImage(im,
                    positions[FieldBoxPositions.URX.ordinal()] - positions[FieldBoxPositions.LLX.ordinal()], 0,
                    0, positions[FieldBoxPositions.URY.ordinal()] - positions[FieldBoxPositions.LLY.ordinal()],
                    positions[FieldBoxPositions.LLX.ordinal()], positions[FieldBoxPositions.LLY.ordinal()]);
        } else {
            content.addImage(im, im.getWidth(), 0, 0, im.getHeight(), positions[1], positions[2]);
        }
    } else if (value instanceof Date) {
        // format par dfaut date
        valueStr = DateFormat.getDateInstance(DateFormat.SHORT).format(value);
        form.setField(nomField.toString(), valueStr);
    } else if (value instanceof Boolean) {
        // format par spcial pour Checkbox
        if (Boolean.TRUE.equals(value)) {
            valueStr = "Yes";
        } else {
            valueStr = "No";
        }
        form.setField(nomField.toString(), valueStr);
    } else {
        // format par dfaut
        valueStr = value.toString();
        form.setField(nomField.toString(), valueStr);
    }
}

From source file:org.ejbca.core.model.hardtoken.profiles.SVGImageManipulator.java

/**
 * Returns the message with userspecific data replaced.
 *
 *
 * @return A processed notification message.
 *     /*from w  w w .j av a 2  s. c  o  m*/
 */
public Printable print(EndEntityInformation userdata, String[] pincodes, String[] pukcodes, String hardtokensn,
        String copyoftokensn) throws IOException, PrinterException {
    // Initialize
    DNFieldExtractor dnfields = new DNFieldExtractor(userdata.getDN(), DNFieldExtractor.TYPE_SUBJECTDN);
    // DNFieldExtractor subaltnamefields = new DNFieldExtractor(dn,DNFieldExtractor.TYPE_SUBJECTALTNAME);
    Date currenttime = new Date();
    String startdate = DateFormat.getDateInstance(DateFormat.SHORT).format(currenttime);

    String enddate = DateFormat.getDateInstance(DateFormat.SHORT)
            .format(new Date(currenttime.getTime() + (this.validityms)));
    String hardtokensnwithoutprefix = hardtokensn.substring(this.hardtokensnprefix.length());
    String copyoftokensnwithoutprefix = copyoftokensn.substring(this.hardtokensnprefix.length());

    final SVGOMDocument clone = (SVGOMDocument) svgdoc.cloneNode(true);
    // Get Text rows
    process("text", userdata, dnfields, pincodes, pukcodes, hardtokensn, hardtokensnwithoutprefix,
            copyoftokensn, copyoftokensnwithoutprefix, startdate, enddate, clone);
    process("svg:text", userdata, dnfields, pincodes, pukcodes, hardtokensn, hardtokensnwithoutprefix,
            copyoftokensn, copyoftokensnwithoutprefix, startdate, enddate, clone);

    // Add Image
    /**
    if(userdata.hasimage()){
      addImage(userdata);       
    } 
     */
    insertImage(userdata, clone); // special dravel for demo

    PrintTranscoder t = new PrintTranscoder();
    TranscoderInput input = new TranscoderInput(clone);
    TranscoderOutput output = new TranscoderOutput(new ByteArrayOutputStream());
    t.transcode(input, output);
    {
        final String aDoNot = clone.getRootElement().getAttribute("doNotScaleToPage");
        t.addTranscodingHint(PrintTranscoder.KEY_SCALE_TO_PAGE,
                Boolean.valueOf(aDoNot == null || aDoNot.trim().length() <= 0));
    }
    return t;
}