我无法将日期格式更改为dd/MMM/yyyy
.
这是我当前的实现:
final String OLD_FORMAT = "yyyy-MM-dd";
final String NEW_FORMAT = "yyyy-MMM-dd";
//Start Date
String str4=label.getText();
java.util.Date toDate = null;
//System.out.println(str4);
//End Date
String str5=lblNewLabel_3.getText();
java.util.Date newDateString = null;
SimpleDateFormat format = new SimpleDateFormat(OLD_FORMAT);
try {
toDate=format.parse(str4);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
newDateString=format.parse(str5);
format.applyLocalizedPattern(NEW_FORMAT);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
输出:[2013 年 5 月 28 日星期二 00:00:00 WST]
有人可以帮我解决这个问题吗,谢谢!:D
我添加了这个while语句,然后日期格式再次设置为默认值..
System.out.println("From " + toDate);
System.out.println("To " + newDateString );
Calendar cal2 = Calendar.getInstance();
cal2.setTime(toDate);
System.out.println(toDate);
while (cal2.getTime().before(newDateString)) {
cal2.add(Calendar.DATE, 1);
Object datelist=(cal2.getTime());
List<Object> wordList = Arrays.asList(datelist);
System.out.println(wordList);
}