Example usage for android.text.format DateUtils FORMAT_NUMERIC_DATE

List of usage examples for android.text.format DateUtils FORMAT_NUMERIC_DATE

Introduction

In this page you can find the example usage for android.text.format DateUtils FORMAT_NUMERIC_DATE.

Prototype

int FORMAT_NUMERIC_DATE

To view the source code for android.text.format DateUtils FORMAT_NUMERIC_DATE.

Click Source Link

Usage

From source file:Main.java

public static String formatMediumDate(Context context, Calendar date) {
    return getAbbrevDayOfWeekString(date.get(Calendar.DAY_OF_WEEK)) + ", "
            + DateUtils.formatDateTime(context, date.getTimeInMillis(), DateUtils.FORMAT_NUMERIC_DATE);
}

From source file:de.incoherent.suseconferenceclient.app.SocialWrapper.java

public static ArrayList<SocialItem> getTwitterItems(Context context, String tag, int maximum) {
    String twitterSearch = "http://search.twitter.com/search.json?q=" + tag;
    ArrayList<SocialItem> socialItems = new ArrayList<SocialItem>();

    // TODO Android 2.2 thinks that "Wed, 19 Sep 2012 16:35:43 +0000" is invalid
    // with this formatter
    SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
    formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
    try {//  ww w .  j av  a 2 s.  co  m
        Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.twitter_icon);
        JSONObject result = HTTPWrapper.get(twitterSearch);
        JSONArray items = result.getJSONArray("results");
        int len = items.length();
        if ((len > 0) && (maximum > 0) && (len > maximum))
            len = maximum;

        for (int i = 0; i < len; i++) {
            JSONObject jsonItem = items.getJSONObject(i);
            Bitmap image = HTTPWrapper.getImage(jsonItem.getString("profile_image_url"));
            Date formattedDate = new Date();
            try {
                formattedDate = formatter.parse(jsonItem.getString("created_at"));
            } catch (ParseException e) {
                Log.d("SUSEConferences", "Invalid date string: " + jsonItem.getString("created_at"));
                e.printStackTrace();
            }
            String user = jsonItem.getString("from_user");
            SocialItem newItem = new SocialItem(SocialItem.TWITTER, user, jsonItem.getString("text"),
                    formattedDate,
                    DateUtils
                            .formatDateTime(context, formattedDate.getTime(),
                                    DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_NUMERIC_DATE
                                            | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE),
                    image, icon);
            String link = "http://twitter.com/" + user + "/status/" + jsonItem.getString("id_str");
            newItem.setLink(link);
            socialItems.add(newItem);
        }
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return socialItems;
}

From source file:com.adam.aslfms.util.Util.java

/**
 * Converts time from a long to a string in a format set by the user in the
 * phone's settings./*from  w ww. jav  a  2s.  c o m*/
 *
 * @param ctx  context to get access to the conversion methods
 * @param secs time since 1970, UTC, in seconds
 * @return the time since 1970, UTC, as a string (e.g. 2009-10-23 12:25)
 */
public static String timeFromUTCSecs(Context ctx, long secs) {
    return DateUtils.formatDateTime(ctx, secs * 1000,
            DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NUMERIC_DATE);
}

From source file:com.jaspersoft.android.jaspermobile.activities.storage.adapter.FileAdapter.java

private String getFormattedDateModified(File file) {
    return DateUtils.formatDateTime(getContext(), file.lastModified(),
            DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR
                    | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_24HOUR);
}

From source file:de.incoherent.suseconferenceclient.app.SocialWrapper.java

public static ArrayList<SocialItem> getGooglePlusItems(Context context, String tag, int maximum) {
    String twitterSearch = "https://www.googleapis.com/plus/v1/activities?orderBy=recent&query=" + tag + "&key="
            + Config.PLUS_KEY;/*w  w w. j a v  a  2s.co m*/
    Log.d("SUSEConferences", "Google search: " + twitterSearch);
    ArrayList<SocialItem> socialItems = new ArrayList<SocialItem>();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
    formatter.setTimeZone(TimeZone.getTimeZone("UTC"));

    Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.google_icon);

    try {
        JSONObject result = HTTPWrapper.get(twitterSearch);
        JSONArray items = result.getJSONArray("items");
        int len = items.length();
        if ((len > 0) && (maximum > 0) && (len > maximum))
            len = maximum;

        for (int i = 0; i < len; i++) {
            JSONObject jsonItem = items.getJSONObject(i);
            JSONObject actorItem = jsonItem.getJSONObject("actor");
            JSONObject imageItem = actorItem.getJSONObject("image");
            JSONObject objectItem = jsonItem.getJSONObject("object");
            Bitmap image = HTTPWrapper.getImage(imageItem.getString("url"));
            String content = Html.fromHtml(objectItem.getString("content")).toString();
            Date formattedDate = new Date();
            try {
                formattedDate = formatter.parse(jsonItem.getString("published"));
            } catch (ParseException e) {
                e.printStackTrace();
            }

            SocialItem newItem = new SocialItem(SocialItem.GOOGLE, actorItem.getString("displayName"), content,
                    formattedDate,
                    DateUtils
                            .formatDateTime(context, formattedDate.getTime(),
                                    DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_NUMERIC_DATE
                                            | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE),
                    image, icon);
            newItem.setLink(jsonItem.getString("url"));
            socialItems.add(newItem);
        }
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (SocketException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return socialItems;
}

From source file:com.adam.aslfms.util.Util.java

public static String timeFromLocalMillis(Context ctx, long millis) {
    return DateUtils.formatDateTime(ctx, millis,
            DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NUMERIC_DATE);
}

From source file:be.billington.calendar.recurrencepicker.RecurrencePickerDialog.java

public void updateDialog() {
    // Interval//from   w  w  w  .j  a  v  a 2s  .c om
    // Checking before setting because this causes infinite recursion
    // in afterTextWatcher
    final String intervalStr = Integer.toString(mModel.interval);
    if (!intervalStr.equals(mInterval.getText().toString())) {
        mInterval.setText(intervalStr);
    }

    mFreqSpinner.setSelection(mModel.freq);
    mWeekGroup.setVisibility(mModel.freq == RecurrenceModel.FREQ_WEEKLY ? View.VISIBLE : View.GONE);
    mWeekGroup2.setVisibility(mModel.freq == RecurrenceModel.FREQ_WEEKLY ? View.VISIBLE : View.GONE);
    mMonthGroup.setVisibility(mModel.freq == RecurrenceModel.FREQ_MONTHLY ? View.VISIBLE : View.GONE);

    switch (mModel.freq) {
    case RecurrenceModel.FREQ_DAILY:
        mIntervalResId = R.plurals.recurrence_interval_daily;
        break;

    case RecurrenceModel.FREQ_WEEKLY:
        mIntervalResId = R.plurals.recurrence_interval_weekly;
        for (int i = 0; i < 7; i++) {
            mWeekByDayButtons[i].setChecked(mModel.weeklyByDayOfWeek[i]);
        }
        break;

    case RecurrenceModel.FREQ_MONTHLY:
        mIntervalResId = R.plurals.recurrence_interval_monthly;

        if (mModel.monthlyRepeat == RecurrenceModel.MONTHLY_BY_DATE) {
            mMonthRepeatByRadioGroup.check(R.id.repeatMonthlyByNthDayOfMonth);
        } else if (mModel.monthlyRepeat == RecurrenceModel.MONTHLY_BY_NTH_DAY_OF_WEEK) {
            mMonthRepeatByRadioGroup.check(R.id.repeatMonthlyByNthDayOfTheWeek);
        }

        if (mMonthRepeatByDayOfWeekStr == null) {
            if (mModel.monthlyByNthDayOfWeek == 0) {
                mModel.monthlyByNthDayOfWeek = (mTime.monthDay + 6) / 7;
                // Since not all months have 5 weeks, we convert 5th NthDayOfWeek to
                // -1 for last monthly day of the week
                if (mModel.monthlyByNthDayOfWeek >= FIFTH_WEEK_IN_A_MONTH) {
                    mModel.monthlyByNthDayOfWeek = LAST_NTH_DAY_OF_WEEK;
                }
                mModel.monthlyByDayOfWeek = mTime.weekDay;
            }

            String[] monthlyByNthDayOfWeekStrs = mMonthRepeatByDayOfWeekStrs[mModel.monthlyByDayOfWeek];

            // TODO(psliwowski): Find a better way handle -1 indexes
            int msgIndex = mModel.monthlyByNthDayOfWeek < 0 ? FIFTH_WEEK_IN_A_MONTH
                    : mModel.monthlyByNthDayOfWeek;
            mMonthRepeatByDayOfWeekStr = monthlyByNthDayOfWeekStrs[msgIndex - 1];
            mRepeatMonthlyByNthDayOfWeek.setText(mMonthRepeatByDayOfWeekStr);
        }
        break;

    case RecurrenceModel.FREQ_YEARLY:
        mIntervalResId = R.plurals.recurrence_interval_yearly;
        break;
    }
    updateIntervalText();
    updateDoneButtonState();

    mEndSpinner.setSelection(mModel.end);
    if (mModel.end == RecurrenceModel.END_BY_DATE) {
        final String dateStr = DateUtils.formatDateTime(getActivity(), mModel.endDate.toMillis(false),
                DateUtils.FORMAT_NUMERIC_DATE);
        mEndDateTextView.setText(dateStr);
    } else {
        if (mModel.end == RecurrenceModel.END_BY_COUNT) {
            // Checking before setting because this causes infinite
            // recursion
            // in afterTextWatcher
            final String countStr = Integer.toString(mModel.endCount);
            if (!countStr.equals(mEndCount.getText().toString())) {
                mEndCount.setText(countStr);
            }
        }
    }
}

From source file:com.codetroopers.betterpickers.recurrencepicker.RecurrencePickerDialogFragment.java

public void updateDialog() {
    // Interval/*from   w  ww .j  a v a2 s.  c o m*/
    // Checking before setting because this causes infinite recursion
    // in afterTextWatcher
    final String intervalStr = Integer.toString(mModel.interval);
    if (!intervalStr.equals(mInterval.getText().toString())) {
        mInterval.setText(intervalStr);
    }

    mFreqSpinner.setSelection(mModel.freq);
    mWeekGroup.setVisibility(mModel.freq == RecurrenceModel.FREQ_WEEKLY ? View.VISIBLE : View.GONE);
    mWeekGroup2.setVisibility(mModel.freq == RecurrenceModel.FREQ_WEEKLY ? View.VISIBLE : View.GONE);
    mMonthGroup.setVisibility(mModel.freq == RecurrenceModel.FREQ_MONTHLY ? View.VISIBLE : View.GONE);

    switch (mModel.freq) {
    case RecurrenceModel.FREQ_HOURLY:
        mIntervalResId = R.plurals.recurrence_interval_hourly;
        break;
    case RecurrenceModel.FREQ_DAILY:
        mIntervalResId = R.plurals.recurrence_interval_daily;
        break;

    case RecurrenceModel.FREQ_WEEKLY:
        mIntervalResId = R.plurals.recurrence_interval_weekly;
        for (int i = 0; i < 7; i++) {
            mWeekByDayButtons[i].setChecked(mModel.weeklyByDayOfWeek[i]);
        }
        break;

    case RecurrenceModel.FREQ_MONTHLY:
        mIntervalResId = R.plurals.recurrence_interval_monthly;

        if (mModel.monthlyRepeat == RecurrenceModel.MONTHLY_BY_DATE) {
            mMonthRepeatByRadioGroup.check(R.id.repeatMonthlyByNthDayOfMonth);
        } else if (mModel.monthlyRepeat == RecurrenceModel.MONTHLY_BY_NTH_DAY_OF_WEEK) {
            mMonthRepeatByRadioGroup.check(R.id.repeatMonthlyByNthDayOfTheWeek);
        }

        if (mMonthRepeatByDayOfWeekStr == null) {
            if (mModel.monthlyByNthDayOfWeek == 0) {
                mModel.monthlyByNthDayOfWeek = (mTime.monthDay + 6) / 7;
                // Since not all months have 5 weeks, we convert 5th NthDayOfWeek to
                // -1 for last monthly day of the week
                if (mModel.monthlyByNthDayOfWeek >= FIFTH_WEEK_IN_A_MONTH) {
                    mModel.monthlyByNthDayOfWeek = LAST_NTH_DAY_OF_WEEK;
                }
                mModel.monthlyByDayOfWeek = mTime.weekDay;
            }

            String[] monthlyByNthDayOfWeekStrs = mMonthRepeatByDayOfWeekStrs[mModel.monthlyByDayOfWeek];

            // TODO(psliwowski): Find a better way handle -1 indexes
            int msgIndex = mModel.monthlyByNthDayOfWeek < 0 ? FIFTH_WEEK_IN_A_MONTH
                    : mModel.monthlyByNthDayOfWeek;
            mMonthRepeatByDayOfWeekStr = monthlyByNthDayOfWeekStrs[msgIndex - 1];
            mRepeatMonthlyByNthDayOfWeek.setText(mMonthRepeatByDayOfWeekStr);
        }
        break;

    case RecurrenceModel.FREQ_YEARLY:
        mIntervalResId = R.plurals.recurrence_interval_yearly;
        break;
    }
    updateIntervalText();
    updateDoneButtonState();

    mEndSpinner.setSelection(mModel.end);
    if (mModel.end == RecurrenceModel.END_BY_DATE) {
        final String dateStr = DateUtils.formatDateTime(getActivity(), mModel.endDate.toMillis(false),
                DateUtils.FORMAT_NUMERIC_DATE);
        mEndDateTextView.setText(dateStr);
    } else {
        if (mModel.end == RecurrenceModel.END_BY_COUNT) {
            // Checking before setting because this causes infinite
            // recursion
            // in afterTextWatcher
            final String countStr = Integer.toString(mModel.endCount);
            if (!countStr.equals(mEndCount.getText().toString())) {
                mEndCount.setText(countStr);
            }
        }
    }
}

From source file:cgeo.geocaching.cgBase.java

/**
 * Generate a numeric date string according to system-wide settings (locale, date format)
 * such as "10/20/2010"./* w  ww .j a  va 2  s. c om*/
 *
 * @param date
 *            milliseconds since the epoch
 * @return the formatted string
 */
public String formatShortDate(long date) {
    return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NUMERIC_DATE);
}