Just some code to switch the DateBox from a U.S. date into a dd/mm/
yyyy format (for countries like Australia).

Set the format in the date box:
myDateBox.setFormat(new AustralianDateFormat());

--- And here is the formatter ---

import java.util.Date;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.datepicker.client.DateBox;
import com.google.gwt.user.datepicker.client.DateBox.Format;

/**
 * Uses the default formatter, except swaps the day and month around
when entering.
 * Eg: 5/1/80 = 5 Jan 1980
 *
 * @author Craig Mitchell
 * @date 29 Oct 2009
 */
public class AustralianDateFormat implements Format {
        private DateBox.DefaultFormat defaultFormatter;

        public AustralianDateFormat() {
                defaultFormatter = new 
DateBox.DefaultFormat(DateTimeFormat.getFormat
("d MMM, yyyy"));
        }

        public Date parse(DateBox dateBox, String text, boolean reportError)
{
                // Swap the day and month around before parsing
                if (text != null) {
                        String[] parts = text.split("/");

                        if (parts.length == 3) {
                                text = parts[1] + "/" + parts[0] + "/" + 
parts[2];
                        }
                }

                return defaultFormatter.parse(dateBox, text, reportError);
        }

        public String format(DateBox dateBox, Date date) {
                return defaultFormatter.format(dateBox, date);
        }

        public void reset(DateBox dateBox, boolean abandon) {
                defaultFormatter.reset(dateBox, abandon);
        }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to