Android的DateFormatting [英] Android DateFormatting
本文介绍了Android的DateFormatting的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//The First Code
/*private String getDisplayTime(String datetime) {
try {
Date dt = sdf.parse(datetime);
if (now.getYear()==dt.getYear() && now.getMonth()==dt.getMonth() && now.getDate()==dt.getDate()) {
return df[1].format(dt);
}
return df[0].format(dt);
} catch (ParseException e) {
return datetime;
}
}*/
//The second code
private String getDisplayTime(String dateTime) {
try {
//Date dt = sdf.parse(dateTime);
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
sdf.setCalendar(cal);
sdf.parse(dateTime);
if ( cal1.get(cal1.YEAR)==cal.get(cal.YEAR) && cal1.get(cal1.MONTH)==cal.get(cal.MONTH) && cal1.get(cal1.DATE)==cal.get(cal.DATE)) {
return df[1].format(cal); }
} catch (ParseException e) {
}
return dateTime;
}
上面的code是两个,但首先是真实的。但是,该格式已经去pcated所以我不能用它$ P $。所以,我做了第二次测试它,但我没有得到我所需要的输出...请帮助我。谢谢。
The Code above are two, but the first is the real one. But, the format has been deprecated so I can't use it. So, I did the second to test it, but I'm not getting the output I needed...Please Help me Out. Thank You.
推荐答案
String[] formats = new String[] {
"yyyy-MM-dd",
"yyyy-MM-dd HH:mm",
"yyyy-MM-dd HH:mmZ",
"yyyy-MM-dd HH:mm:ss.SSSZ",
"yyyy-MM-dd'T'HH:mm:ss.SSSZ",
};
for (String format : formats) {
SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US);
System.out.format("%30s %s\n", format, sdf.format(new Date(0)));
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.format("%30s %s\n", format, sdf.format(new Date(0)));
}
试着问这个问题之前,下一次搜索的东西,也有很多在Android的日期格式化的例子。或者让你的问题更清楚。
Try to search something next time before asking the question, there are a lot of examples of Date formating in Android. Or make your question more clear.
这篇关于Android的DateFormatting的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文