We are using SmartGWT 3.0 Pro license.
Here is my problem:
I use a DateItem and want to show the date this way in the GUI: dd.MM.yyyy (e.g. 21.12.2012). I tried many different alternatives (as you can see in the source code below), I read a lot in forum discussions (e.g. http://forums.smartclient.com/showthread.php?p=49801#post49801), but it does not work.
I have attached a screenshot of the result, the date is always shown this way in the GUI: dd/MM/yyyy
Please tell me how to display the date as I need it... Thank you.
Here is my problem:
I use a DateItem and want to show the date this way in the GUI: dd.MM.yyyy (e.g. 21.12.2012). I tried many different alternatives (as you can see in the source code below), I read a lot in forum discussions (e.g. http://forums.smartclient.com/showthread.php?p=49801#post49801), but it does not work.
I have attached a screenshot of the result, the date is always shown this way in the GUI: dd/MM/yyyy
Please tell me how to display the date as I need it... Thank you.
Code:
DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() {
public String format(Date date) {
if(date == null) return null;
//you'll probably want to create the DateTimeFormat outside this method.
//here for illustration purposes
DateTimeFormat dateFormatter = DateTimeFormat.getFormat("dd.MM.yyyy");
String format = dateFormatter.format(date);
return format;
}
});
DateUtil.setNormalDateDisplayFormatter(new DateDisplayFormatter() {
public String format(Date date) {
if(date == null) return null;
//you'll probably want to create the DateTimeFormat outside this method.
//here for illustration purposes
DateTimeFormat dateFormatter = DateTimeFormat.getFormat("dd.MM.yyyy");
String format = dateFormatter.format(date);
// SC.say("DateString: " + date.toString() + "<br>FormatString" + format);
return format;
}
});
// DateUtil.setDateInputFormatter(new DateInputFormatter() {
// @Override
// public Date parse(String dateString) {
// String[] parts = dateString.split("\\.");
// int[] numbers = new int[3];
//
// for(int i=0; i<=parts.length - 1; i++)
// numbers[i] = Integer.parseInt(parts[i]);
//
// Date d = new Date();
// d.setDate(numbers[0]);
// d.setYear(numbers[2] - 1900);
// d.setMonth(numbers[1] - 1);
//
// return d;
// }
// });
// DateUtil.setDateInputFormatter(new DateInputFormatter() {
// public Date parse(String dateString) {
// final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("dd.MM.yyyy");
// Date date = dateFormatter.parse(dateString);
// return date;
// }
// });
DateUtil.setDateParser(new DateParser() {
public Date parse(String dateString) {
final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("dd.MM.yyyy");
Date date = dateFormatter.parse(dateString);
return date;
}
});
// DateUtil.setDateInputFormat("dd.MM.yyyy");
baselineDateItem = new DateItem("baselineDate", "Baseline Date");
// baselineDateItem.setDateFormatter(DateDisplayFormat.);
baselineDateItem.setUseTextField(true);
baselineDateItem.setUseMask(true);
// baselineDateItem.setAttribute("dateFormatter", "toNormalDate");
// baselineDateTimeItem.setDisplayFormat(DateDisplayFormat.TOEUROPEANSHORTDATETIME);
// baselineDateItem.setDateFormatter(new DateDisplayFormatter() {
// public String format(Date date) {
// if(date == null) return null;
// //you'll probably want to create the DateTimeFormat outside this method.
// //here for illustration purposes
// DateTimeFormat dateFormatter = DateTimeFormat.getFormat("dd.MM.yyyy");
// String format = dateFormatter.format(date);
// return format;
// }
// });