long型的时间转换为时间格式 短信模块用到
2013-01-16 10:12
232 查看
//如果为今天,则显示时间(如2013年1月16日),如果不是今天则显示日期(今天10:15)
private String getDate(long dateTime)
{
int flags = 0;
String date = "";
if (DateUtils.isToday(dateTime))
{
flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_24HOUR;
date = "今天"+(String)DateUtils.formatDateTime(mContext, dateTime, flags);
}
else
{
flags = DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
date = (String)DateUtils.formatDateTime(mContext, dateTime, flags);
}
return date;
}
方法二:/如果不是今年,则显示时间(如2012-1-16),是是今年非今天则显示月日1月15日,如果是今天则显示日期(上午10:15)
public static String formatTimeStampString(Context context, long when) {
return formatTimeStampString(context, when, false);
}
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://www.linuxidc.com/Linux/2012-08/68510.htm
private String getDate(long dateTime)
{
int flags = 0;
String date = "";
if (DateUtils.isToday(dateTime))
{
flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_24HOUR;
date = "今天"+(String)DateUtils.formatDateTime(mContext, dateTime, flags);
}
else
{
flags = DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
date = (String)DateUtils.formatDateTime(mContext, dateTime, flags);
}
return date;
}
方法二:/如果不是今年,则显示时间(如2012-1-16),是是今年非今天则显示月日1月15日,如果是今天则显示日期(上午10:15)
public static String formatTimeStampString(Context context, long when) {
return formatTimeStampString(context, when, false);
}
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://www.linuxidc.com/Linux/2012-08/68510.htm
相关文章推荐
- java-转换时间日期格式字串为long型
- js获取当前时间,并将标准日期格式转换成Long型
- python sys,os,time模块的使用(包括时间格式的各种转换)
- 将一个long型值的时间转换成时间格式
- Python中time模块和datetime模块的常用操作以及几种常用时间格式间的转换
- 将时间戳转换成日期格式
- linux下如何把时间转成秒数,或把秒数转换成标准时间格式
- mysql 时间戳与日期格式的相互转换
- 在JSP页面转换时间格式
- Java时间日期格式的转换
- Python模块--struct 数据格式转换
- mysql 时间戳与日期格式的相互转换
- 在Java中获取时间,输出格式设置和与String的转换
- oracle常用& to_date()怎么转换带am pm的时间格式?
- java 时间格式 转换大全 终结版
- mysql数据库语句 的case when用法,以及数据替换,字符串拼接,时间格式转换的用法
- 常见时间格式的转换方式
- Java时间戳与日期格式直接的互相转换(1:将系统日期格式转为时间戳。2:将指定日期转为时间戳。3:将系统时间戳转为日期格式。4将指定的时间戳转为日期格式)
- Excel将秒转换成标准的时间格式HH:MM:SS
- 日文和英文系统不同格式时间的取得转换成为“2009-05-22”形式