Android Long to Date Convert formatTimeStampString(Context context, long when, boolean fullFormat)

Here you can find the source of formatTimeStampString(Context context, long when, boolean fullFormat)

Description

format Time Stamp String

License

Open Source License

Declaration

public static String formatTimeStampString(Context context, long when,
            boolean fullFormat) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;
import android.text.format.DateUtils;
import android.text.format.Time;

public class Main {
    public static String formatTimeStampString(Context context, long when,
            boolean fullFormat) {
        Time then = new Time();
        then.set(when);//from   ww w . j av a2 s .  com
        Time now = new Time();
        now.setToNow();

        int format_flags = DateUtils.FORMAT_CAP_NOON_MIDNIGHT
                | DateUtils.FORMAT_CAP_AMPM;
        if (then.year != now.year) {
            format_flags |= DateUtils.FORMAT_SHOW_YEAR
                    | DateUtils.FORMAT_SHOW_DATE;
        } else if (then.yearDay != now.yearDay) {
            format_flags |= DateUtils.FORMAT_SHOW_DATE;
        } else {
            format_flags |= DateUtils.FORMAT_SHOW_TIME;
        }

        if (fullFormat) {
            format_flags |= (DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
        }

        return DateUtils.formatDateTime(context, when, format_flags);
    }
}

Related

  1. getCurrentDate(long time)
  2. changeMillisToFormat(long milliseconds, String pattern)
  3. convertLongToDateString(long mills, String format)
  4. format(String pattern, long timeInMillis)
  5. formatDateD(Context paramContext, long paramLong)
  6. getDatesStartingFromToWithInterval( long startDate, long endDate, int dayInterval)
  7. getFormatDateString(String format, long date)
  8. getLongFriendlyDate(long timeInMillis)
  9. getShortFriendlyDate(long timeInMillis)