Announcement Announcement Module
No announcement yet.
Need help with Custom date formatters in spring 3.0 Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help with Custom date formatters in spring 3.0

    Hi i need to parse date format passed to webservice to specific format.
    i tried below changes in application-context.xml but still no luck with it. Any help will be deeply appreciated. thanks

    HTML Code:
        <mvc:annotation-driven conversion-service="conversionService" />
       <bean id="conversionService" class=""> 
       	<property name="converters"> 
       			<bean class="ws.marshaller.DateFormatter"/> 
    HTML Code:
    package ws.marshaller;
    import java.text.DateFormat ;
    import java.text.ParseException ;
    import java.text.SimpleDateFormat ;
    import java.util.Date ;
    import java.util.Locale ;
    import org.springframework.format.Formatter ;
    	public final class DateFormatter implements Formatter<Date> {
        private String pattern="yyyy-MM-dd'T'hh:mmss";
        public DateFormatter(String pattern) {
            this.pattern = pattern;
        public String print(Date date, Locale locale) {
            if (date == null) {
                return "";
            return getDateFormat(locale).format(date);
        public Date parse(String formatted, Locale locale) throws ParseException {
            if (formatted.length() == 0) {
                return null;
            return getDateFormat(locale).parse(formatted);
        protected DateFormat getDateFormat(Locale locale) {
            DateFormat dateFormat = new SimpleDateFormat(this.pattern, locale);
            return dateFormat;
    Last edited by vivek d r; Jan 25th, 2013, 12:24 AM.