我想在列表视图中显示当前日期的日期。如何自定义该日期。请任何人告诉我。例如,当您在铁路预订机票时,它显示当前日期 - wards。就像我想要实现的那样。
![enter image description here][1]
[1]: http://i.stack.imgur.com/3NPXA.png
答案 0 :(得分:0)
代码检查日期在之后 今天。
Calendar c = Calendar.getInstance();
// set the calendar to start of today
c.set(Calendar.HOUR, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
// and get that as a Date
Date today = c.getTime();
// or as a timestamp in milliseconds
long todayInMillis = c.getTimeInMillis();
// user-specified date which you are testing
// let's say the components come from a form or something
int year = 2011;
int month = 5;
int dayOfMonth = 20;
// reuse the calendar to set user specified date
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
// and get that as a Date
Date dateSpecified = c.getTime();
// test your condition
if (dateSpecified.before(today)) {
System.err.println("Date specified [" + dateSpecified + "] is before today [" + today + "]");
} else {
System.err.println("Date specified [" + dateSpecified + "] is NOT before today [" + today + "]");
}
完成强>
答案 1 :(得分:0)
使用SimpleDateFormat例如
Date d = new Date();
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("c - LLLL");
String formattedDate = simpleDateFormat.format(d);//Mon - June for that format
中的格式(yyyy,dd ...)
希望这会有所帮助。