// target is string
if (String.class.equals(target)) {
final SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC")); // we DO work only with UTC times
return new Converter() {
public Object convert(Object source, Class target) throws Exception {
if(source instanceof Date){
return df.format((Date) source);
}
return null;
}
};
}
}
// this should handle java.util.Calendar to
// String
if (Calendar.class.isAssignableFrom(source)) {
// target is string
if (String.class.equals(target)) {
final SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC")); // we DO work only with UTC times
return new Converter() {
public Object convert(Object source, Class target) throws Exception {
if(source instanceof Calendar){
return df.format(((Calendar) source).getTime());
}
return null;
}
};
}
}
if (XMLGregorianCalendar.class.isAssignableFrom(source)) {
// target is string
if (String.class.equals(target)) {
final SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC")); // we DO work only with UTC times
return new Converter() {
public Object convert(Object source, Class target) throws Exception {
if(source instanceof XMLGregorianCalendar){
return df.format(((XMLGregorianCalendar) source).toGregorianCalendar(TimeZone.getTimeZone("GMT"),Locale.getDefault(),null).getTime());
}
return null;