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:com.dnielfe.manager.adapters.BrowserListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder mViewHolder;
    int num_items = 0;
    final File file = new File(getItem(position));
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault());

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.item_browserlist, parent, false);
        mViewHolder = new ViewHolder(convertView);
        convertView.setTag(mViewHolder);
    } else {/*  w w w.j  a va  2 s  .c  o  m*/
        mViewHolder = (ViewHolder) convertView.getTag();
    }

    if (Settings.mListAppearance > 0) {
        mViewHolder.dateview.setVisibility(TextView.VISIBLE);
    } else {
        mViewHolder.dateview.setVisibility(TextView.GONE);
    }

    if (Settings.showthumbnail)
        setIcon(file, mViewHolder.icon);
    else
        loadFromRes(file, mViewHolder.icon);

    if (file.isFile()) {
        // Shows the size of File
        mViewHolder.bottomView.setText(FileUtils.byteCountToDisplaySize(file.length()));
    } else {
        String[] list = file.list();

        if (list != null)
            num_items = list.length;

        // show the number of files in Folder
        mViewHolder.bottomView.setText(num_items + mResources.getString(R.string.files));
    }

    mViewHolder.topView.setText(file.getName());
    mViewHolder.dateview.setText(df.format(file.lastModified()));

    return convertView;
}

From source file:org.jamwiki.utils.DateUtil.java

/**
 * Given a string, return the matching DateFormat style (SHORT, LONG, etc)
 * or -1 if there is no corresponding style.
 *///  ww w.  j  a v  a2 s.co m
public static int stringToDateFormatStyle(String format) {
    if (StringUtils.equalsIgnoreCase(format, "SHORT")) {
        return DateFormat.SHORT;
    } else if (StringUtils.equalsIgnoreCase(format, "MEDIUM")) {
        return DateFormat.MEDIUM;
    } else if (StringUtils.equalsIgnoreCase(format, "LONG")) {
        return DateFormat.LONG;
    } else if (StringUtils.equalsIgnoreCase(format, "FULL")) {
        return DateFormat.FULL;
    } else if (StringUtils.equalsIgnoreCase(format, "DEFAULT")) {
        return DateFormat.DEFAULT;
    }
    return -1;
}

From source file:org.metawidget.example.struts.addressbook.converter.ToStringConverter.java

@SuppressWarnings("rawtypes")
public Object convert(Class clazz, Object value) {

    if (value == null || "".equals(value)) {
        return null;
    }/* w  w  w. j  a  va2 s .co  m*/

    // Convert enums to their .name() form, not their .toString() form, so that we can
    // use .valueOf() in EnumConverter.

    if (value instanceof Enum) {
        return ((Enum) value).name();
    }

    // Do the Date toString here, as unfortunately it seems
    // org.apache.commons.beanutils.converters.DateConverter.convertToString never
    // gets called?

    if (value instanceof Date) {
        return DateFormat.getDateInstance(DateFormat.SHORT).format((Date) value);
    }

    return value.toString();
}

From source file:DateFormatDemo.java

static public void showTimeStyles(Locale currentLocale) {

    Date today = new Date();
    String result;//from ww  w  .j  a  v  a2 s. co  m
    DateFormat formatter;

    int[] styles = { DateFormat.DEFAULT, DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG,
            DateFormat.FULL };

    System.out.println();
    System.out.println("Locale: " + currentLocale.toString());
    System.out.println();

    for (int k = 0; k < styles.length; k++) {
        formatter = DateFormat.getTimeInstance(styles[k], currentLocale);
        result = formatter.format(today);
        System.out.println(result);
    }
}

From source file:org.kuali.kra.irb.protocol.reference.ProtocolReference.java

private Date convertStringToDate(String stringDate) throws ParseException {
    if (!StringUtils.isBlank(stringDate)) {
        Date date = new Date(DateFormat.getDateInstance(DateFormat.SHORT).parse(stringDate).getTime());
        return date;
    } else {/*from   www. ja v  a2 s . c  o m*/
        return null;
    }
}

From source file:ispok.converter.BirthDateConverter.java

@Override
public String getAsString(FacesContext fc, UIComponent uic, Object o) {

    Locale locale = fc.getViewRoot().getLocale();
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);

    SimpleDateFormat sdf = (SimpleDateFormat) df;
    String pattern = sdf.toPattern();

    pattern = pattern.replace("yy", "yyyy");

    Date date = (Date) o;/*from  w  ww  .j av  a2 s  .  c o m*/

    sdf.applyPattern(pattern);

    return sdf.format(date);
}

From source file:org.idansof.otp.client.Planner.java

public PlanResult generatePlan(PlanRequest planRequest)
        throws IOException, XmlPullParserException, ParseException {

    AndroidHttpClient androidHttpClient = AndroidHttpClient.newInstance("");
    try {/*from w w w  . j  a  va 2s. c  om*/

        DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);
        DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, locale);

        Uri.Builder builder = Uri.parse("http://" + host).buildUpon();

        builder.appendEncodedPath(uri);
        builder.appendQueryParameter("fromPlace", planRequest.getFrom().getCoordinateString());
        builder.appendQueryParameter("toPlace", planRequest.getTo().getCoordinateString());
        builder.appendQueryParameter("date", dateFormat.format(planRequest.getDate()));
        builder.appendQueryParameter("time", timeFormat.format(planRequest.getDate()));

        HttpProtocolParams.setContentCharset(androidHttpClient.getParams(), "utf-8");
        String uri = builder.build().toString();
        Log.i(Planner.class.toString(), "Fetching plan from " + uri);
        HttpUriRequest httpUriRequest = new HttpGet(uri);
        httpUriRequest.setHeader("Accept", "text/xml");
        HttpResponse httpResponse = androidHttpClient.execute(httpUriRequest);

        InputStream contentStream = httpResponse.getEntity().getContent();
        Log.i(Planner.class.toString(),
                "Parsing content , size :" + httpResponse.getEntity().getContentLength());
        return parseXMLResponse(contentStream);
    } finally {
        androidHttpClient.close();
    }
}

From source file:org.openmrs.reporting.DrugOrderFilter.java

public String getDescription() {
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Context.getLocale());
    StringBuffer ret = new StringBuffer();
    boolean currentlyCase = getWithinLastDays() != null && getWithinLastDays() == 0
            && (getWithinLastMonths() == null || getWithinLastMonths() == 0);
    if (currentlyCase)
        ret.append("Patients currently ");
    else//w w  w.j  av a  2 s. c  om
        ret.append("Patients ");
    if (getDrugListToUse() == null || getDrugListToUse().size() == 0) {
        if (getAnyOrAll() == GroupMethod.NONE)
            ret.append(currentlyCase ? "taking no drugs" : "who never took any drugs");
        else
            ret.append(currentlyCase ? "taking any drugs" : "ever taking any drugs");
    } else {
        if (getDrugListToUse().size() == 1) {
            if (getAnyOrAll() == GroupMethod.NONE)
                ret.append("not taking ");
            else
                ret.append("taking ");
            ret.append(getDrugListToUse().get(0).getName());
        } else {
            ret.append("taking " + getAnyOrAll() + " of [");
            for (Iterator<Drug> i = getDrugListToUse().iterator(); i.hasNext();) {
                ret.append(i.next().getName());
                if (i.hasNext())
                    ret.append(" , ");
            }
            ret.append("]");
        }
    }
    if (!currentlyCase)
        if (getWithinLastDays() != null || getWithinLastMonths() != null) {
            ret.append(" withing the last");
            if (getWithinLastMonths() != null)
                ret.append(" " + getWithinLastMonths() + " months");
            if (getWithinLastDays() != null)
                ret.append(" " + getWithinLastDays() + " days");
        }
    if (getSinceDate() != null)
        ret.append(" since " + df.format(getSinceDate()));
    if (getUntilDate() != null)
        ret.append(" until " + df.format(getUntilDate()));
    return ret.toString();
}

From source file:com.appeaser.sublimepicker.SublimePickerFragment.java

public SublimePickerFragment() {
    // Initialize formatters
    mDateFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault());
    mTimeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault());
    mTimeFormatter.setTimeZone(TimeZone.getTimeZone("GMT+0"));
}

From source file:com.jaeksoft.searchlib.ClientCatalogItem.java

public String getLastModifiedString() {
    Date dt = getLastModifiedDate();
    if (dt == null)
        return null;
    return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(dt);
}