Java Code Examples for javax.xml.bind.DatatypeConverter#printDate()

The following examples show how to use javax.xml.bind.DatatypeConverter#printDate() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static String printDateToXsdDate(Date value) throws DataConversionException {
    String result = null;
    String valueType = Date.class.getName();
    
    try {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(value);
        result = DatatypeConverter.printDate(calendar);
    } catch(Exception e) {
        if (value != null) valueType = value.getClass().getName();
        logger.fatal("Unable to print "+valueType+" to xsd:date.",e);
        throw new DataConversionException("Unable to print "+valueType+" to xsd:date.", e);
    }
    
    return result;
}
 
Example 2
String formatValue(Object value, String type) {
  if ( value == null ) {
    return "null";
  }
  Class<?> valClass = value.getClass();
  if ( String.class.isAssignableFrom(valClass) ) {
    return (String) value;
  } else if ( type != null &&
    ( type.endsWith("date") || type.endsWith("dateTime") || type.endsWith("time") ) &&
    ( Date.class.isAssignableFrom(valClass) || Calendar.class.isAssignableFrom(valClass) ) )
  {
    if ( Date.class.isAssignableFrom(valClass) ) {
      Calendar cal = Calendar.getInstance();
      cal.setTime((Date) value);
      value = cal;
    }
    if ( type.endsWith("date") ) {
      return DatatypeConverter.printDate((Calendar) value);
    } else if ( type.endsWith("dateTime") ) {
      return DatatypeConverter.printDateTime((Calendar) value);
    } else if ( type.endsWith("time") ) {
      return DatatypeConverter.printTime((Calendar) value);
    }
  }
  return value.toString();
}
 
Example 3
Source Project: cia   File: XmlDateTypeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public String marshal(final Date dt) {
	if (dt == null) {
		return null;
	}
	final Calendar c = Calendar.getInstance();
	c.setTime(dt);
	return DatatypeConverter.printDate(c);
}
 
Example 4
public static String printDate(Date dt) {
    if (dt == null) {
        return null;
    }
    Calendar c = Calendar.getInstance();
    c.setTime(dt);
    return DatatypeConverter.printDate(c);
}
 
Example 5
public static String printDate(Date dt) {
    if (dt == null) {
        return null;
    }
    Calendar c = Calendar.getInstance();
    c.setTime(dt);
    return DatatypeConverter.printDate(c);
}
 
Example 6
public static String printDate(DateTime dateTime) {
   return dateTime == null ? null : DatatypeConverter.printDate(convert(dateTime));
}
 
Example 7
public static String printDate(DateTime dateTime) {
   return dateTime == null ? null : DatatypeConverter.printDate(convert(dateTime));
}
 
Example 8
public static String printDate(DateTime dateTime) {
   return dateTime == null ? null : DatatypeConverter.printDate(convert(dateTime));
}
 
Example 9
public static String printDate(DateTime dateTime) {
   return dateTime == null ? null : DatatypeConverter.printDate(convert(dateTime));
}
 
Example 10
public static String printDate(DateTime dateTime) {
   return dateTime == null ? null : DatatypeConverter.printDate(convert(dateTime));
}
 
Example 11
Source Project: java-client-api   File: XsValueImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return DatatypeConverter.printDate(value);
}
 
Example 12
Source Project: xero-java-client   File: DateAdapter.java    License: Apache License 2.0 4 votes vote down vote up
public static String printDateTime(Date dt) {
  Calendar cal = new GregorianCalendar();
  cal.setTime(dt);
  return DatatypeConverter.printDate(cal);
}
 
Example 13
static String toES(Object dateWritable) {
    DateWritable dw = (DateWritable) dateWritable;
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(dw.get().getTime());
    return DatatypeConverter.printDate(cal);
}