If you want to use any other format except of those which are not supported by SimpleXML, then you need to do little work around for this, You have to write your custom Transform which will handle other other formats and that is not a great deal to do it, really it's so simple.
Put attribute annotation on your date field like this
@Attribute(name="date", required=true)
private Date date;
CustomDateFormatTransformer
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.simpleframework.xml.transform.Transform;
public class CustomDateFormatTransformer implements Transform<Date> {
private DateFormat df;
public DateFormatTransformer(DateFormat df) {
this.df= df;
}
@Override
public Date read(String value) throws Exception {
return df.parse(value);
}
@Override
public String write(Date value) throws Exception {
return df.format(value);
}
}
All things are ready, finally you can call it form you client code as following
DateFormat dateFormat = new SimpleDateFormat("Your_date_format_here");
RegistryMatcher registryMatcher = new RegistryMatcher();
registryMatcher .bind(Date.class, new DateFormatTransformer(dateFormat));
// serialize or Deserializer it here .....
Here are the some formats which are only supported by SimpleXML
yyyy-MM-dd HH:mm:ss.S z, yyyy-MM-dd HH:mm:ss z
yyyy-MM-dd z, yyyy-MM-dd