读书人

[转] android 日期时间格式变换

发布时间: 2013-04-22 16:01:35 作者: rapoo

[转] android 日期时间格式转换

?

android日期时间格式转换:

?

?如果为今天,则显示时间,如果不是今天则显示日期:

public static String formatTimeStampString(Context context, long when, boolean fullFormat) {        Time then = new Time();        then.set(when);        Time now = new Time();        now.setToNow();        // Basic settings for formatDateTime() we want for all cases.        int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT |                           DateUtils.FORMAT_ABBREV_ALL |                           DateUtils.FORMAT_CAP_AMPM;        // If the message is from a different year, show the date and year.        if (then.year != now.year) {            format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;        } else if (then.yearDay != now.yearDay) {            // If it is from a different day than today, show only the date.            format_flags |= DateUtils.FORMAT_SHOW_DATE;        } else {            // Otherwise, if the message is from today, show the time.            format_flags |= DateUtils.FORMAT_SHOW_TIME;        }        // If the caller has asked for full details, make sure to show the date        // and time no matter what we've determined above (but still make showing        // the year only happen if it is a different year from today).        if (fullFormat) {            format_flags |= (DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);        }        return DateUtils.formatDateTime(context, when, format_flags);    }

?

转自http://blog.csdn.net/dany1202/article/details/6164322

?

?

读书人网 >Android

热点推荐