Example usage for android.text.format DateUtils formatDateTime

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

Introduction

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

Prototype

public static String formatDateTime(Context context, long millis, int flags) 

Source Link

Document

Formats a date or a time according to the local conventions.

Usage

From source file:org.mariotaku.twidere.util.Utils.java

@SuppressWarnings("deprecation")
public static void showErrorToast(final Context context, final String action, final Throwable t,
        final boolean long_message) {
    if (context == null)
        return;/*from w  ww .jav  a2 s  . co m*/
    final String message;
    if (t != null) {
        t.printStackTrace();
        final String t_message = trimLineBreak(t.getMessage());
        if (action != null) {
            if (t instanceof TwitterException) {
                final TwitterException te = (TwitterException) t;
                if (te.exceededRateLimitation()) {
                    final RateLimitStatus status = te.getRateLimitStatus();
                    final String next_reset_time_string = DateUtils.formatDateTime(context,
                            status.getResetTime().getTime(),
                            DateFormat.is24HourFormat(context)
                                    ? DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_24HOUR
                                    : DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_12HOUR);
                    message = context.getString(R.string.error_message_rate_limit, action,
                            next_reset_time_string);
                } else {
                    message = context.getString(R.string.error_message_with_action, action, t_message);
                }
            } else {
                message = context.getString(R.string.error_message_with_action, action, t_message);
            }
        } else {
            message = context.getString(R.string.error_message, t_message);
        }
    } else {
        message = context.getString(R.string.error_unknown_error);
    }
    final int length = long_message ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
    final Toast toast = Toast.makeText(context, message, length);
    toast.show();
}

From source file:cgeo.geocaching.cgBase.java

/**
 * Generate a time string according to system-wide settings (locale, 12/24 hour)
 * such as "13:24".//from  w ww  . j ava 2  s.c o m
 *
 * @param date
 *            milliseconds since the epoch
 * @return the formatted string
 */
public String formatTime(long date) {
    return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_TIME);
}

From source file:cgeo.geocaching.cgBase.java

/**
 * Generate a date string according to system-wide settings (locale, date format)
 * such as "20 December" or "20 December 2010". The year will only be included when necessary.
 *
 * @param date//from  ww  w.ja  v  a 2 s  .  c  o m
 *            milliseconds since the epoch
 * @return the formatted string
 */
public String formatDate(long date) {
    return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE);
}

From source file:cgeo.geocaching.cgBase.java

/**
 * Generate a numeric date and time string according to system-wide settings (locale,
 * date format) such as "7 sept.  12:35".
 *
 * @param context//from  www  . j  a v  a2  s  .  c o m
 *            a Context
 * @param date
 *            milliseconds since the epoch
 * @return the formatted string
 */
public static String formatShortDateTime(Context context, long date) {
    return DateUtils.formatDateTime(context, date,
            DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL);
}

From source file:cgeo.geocaching.cgBase.java

/**
 * Generate a date string according to system-wide settings (locale, date format)
 * such as "20 December 2010". The year will always be included, making it suitable
 * to generate long-lived log entries.//from   w w w . ja  va2 s. co m
 *
 * @param date
 *            milliseconds since the epoch
 * @return the formatted string
 */
public String formatFullDate(long date) {
    return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR);
}

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"./*www .  jav  a 2  s.c  o m*/
 *
 * @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);
}