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

The following examples show how to use javax.xml.bind.DatatypeConverter#printDateTime() . 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
File writeProperties(File packageFolder, int articleCount) throws IOException, FileNotFoundException {
    File propertiesFile = new File(packageFolder, IMPORT_PROPERTIES_FILENAME);
    Properties properties = new Properties();
    gcalendar.setTimeInMillis(System.currentTimeMillis());
    String importDate = DatatypeConverter.printDateTime(gcalendar);
    properties.setProperty(PROP_IMPORT_INFODATE, importDate);
    properties.setProperty(PROP_IMPORT_OBJECTS, String.valueOf(articleCount));
    properties.setProperty(PROP_IMPORT_CONTENT_FILES, "0");
    properties.setProperty(PROP_IMPORT_BWMETA_FILES, "1");
    Writer propsWriter = new NoCommentsWriter(new OutputStreamWriter(new FileOutputStream(propertiesFile), Charsets.UTF_8));
    try {
        properties.store(propsWriter, null);
        return propertiesFile;
    } finally {
        propsWriter.close();
    }
}
 
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
public static String printDateToXsdDateTime(Date value) throws DataConversionException {
    String result = null;
    String valueType = Date.class.getName();
    
    try {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(value);
        result = DatatypeConverter.printDateTime(calendar);
    } catch(Exception e) {
        if (value != null) valueType = value.getClass().getName();
        logger.fatal("Unable to print "+valueType+" to xsd:dateTime.",e);
        throw new DataConversionException("Unable to print "+valueType+" to xsd:dateTime.", e);
    }
    
    return result;
}
 
Example 4
Source Project: elasticsearch-hadoop   File: PigUtils.java    License: Apache License 2.0 5 votes vote down vote up
static String convertToES(Object pigDate) {
    if (pigDate instanceof Number) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(((Number) pigDate).longValue());
        return DatatypeConverter.printDateTime(cal);
    }
    if (pigDate instanceof String) {
        return ((String) pigDate);
    }
    throw new EsHadoopIllegalArgumentException(String.format("Cannot convert [%s] to date", pigDate));
}
 
Example 5
/**
 * Visible for testing
 */
public String getTimestamp(E event) {
    long millis = System.currentTimeMillis();
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(millis);
    return DatatypeConverter.printDateTime(cal);
}
 
Example 6
Source Project: cia   File: XmlDateTimeTypeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String marshal(final Date dt) {
	if (dt == null) {
		return null;
	}
	final Calendar c = Calendar.getInstance();
	c.setTime(dt);
	return DatatypeConverter.printDateTime(c);
}
 
Example 7
public static String printDateTime(Date dt) {
    if (dt == null) {
        return null;
    }
    Calendar c = Calendar.getInstance();
    c.setTime(dt);
    return DatatypeConverter.printDateTime(c);
}
 
Example 8
public static String printDate(Date dt) {
    if (dt == null) {
        return null;
    }
    Calendar c = Calendar.getInstance();
    c.setTime(dt);
    String date = DatatypeConverter.printDateTime(c);
    if(date != null && date.contains("+"))
    	date = date.substring(0, date.indexOf("+"));
    
    if(date != null && date.length() > 10) {
    	date = date.substring(0, 10);
    }
    return date;
}
 
Example 9
public static String printDateTime(Date dt) {
    if (dt == null) {
        return null;
    }
    Calendar c = Calendar.getInstance();
    c.setTime(dt);
    return DatatypeConverter.printDateTime(c);
}
 
Example 10
public static String printDate(Date dt) {
    if (dt == null) {
        return null;
    }
    Calendar c = Calendar.getInstance();
    c.setTime(dt);
    String date = DatatypeConverter.printDateTime(c);
    if(date != null && date.contains("+"))
    	date = date.substring(0, date.indexOf("+"));
    
    if(date != null && date.length() > 10) {
    	date = date.substring(0, 10);
    }
    return date;
}
 
Example 11
Source Project: Openfire   File: IQEntityTimeHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the ISO 8601 formatted date (UTC) as specified in XEP-0082: XMPP Date and Time Profiles.
 *
 * @param date The date.
 * @return The UTC formatted date.
 */
String getUtcDate(Date date) {
    // package-private for test.
    Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    calendar.setTime(date);
    // This makes sure the date is formatted as the xs:dateTime type.
    return DatatypeConverter.printDateTime(calendar);
}
 
Example 12
Source Project: olingo-odata4   File: SearchHandler.java    License: Apache License 2.0 5 votes vote down vote up
private static String asString(final Object primitive) {
  // TODO: improve 'string' conversion; maybe consider only String properties
  if (primitive instanceof String) {
    return (String) primitive;
  } else if (primitive instanceof Calendar) {
    return DatatypeConverter.printDateTime((Calendar) primitive);
  } else if (primitive instanceof byte[]) {
    return DatatypeConverter.printBase64Binary((byte[]) primitive);
  } else {
    return primitive.toString();
  }
}
 
Example 13
Source Project: vraptor4   File: CalendarConverter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
	String out = DatatypeConverter.printDateTime((Calendar) source);
	writer.setValue(out);
}
 
Example 14
public static String printDateTime(DateTime dateTime) {
   return dateTime == null ? null : DatatypeConverter.printDateTime(convert(dateTime));
}
 
Example 15
public static String printDateTime(DateTime dateTime) {
   return dateTime == null ? null : DatatypeConverter.printDateTime(convert(dateTime));
}
 
Example 16
Source Project: OpenEstate-IO   File: ImmoXmlUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static String printDateTime(Calendar value) {
    if (value == null)
        throw new IllegalArgumentException("Can't print date-time value!");
    else
        return DatatypeConverter.printDateTime(value);
}
 
Example 17
Source Project: xmlunit   File: DateTimeToDateAdapter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String marshal(final Date value) {
    final Calendar cal = new GregorianCalendar();
    cal.setTime(value);
    return DatatypeConverter.printDateTime(cal);
}
 
Example 18
public static String printDateUpdatedType(Calendar value) {
    if (value == null || !isValidDateUpdatedType(value))
        throw new IllegalArgumentException("Can't print date-updated value!");
    else
        return DatatypeConverter.printDateTime(value);
}
 
Example 19
/**
 * Matches documents with LSQT prior to timestamp
 * @param temporalCollection the temporal collection to query
 * @param time documents with lsqt equal to or prior to this timestamp will match
 * @param weight the weight for this query
 * @param options string options from the list for
 *     <a href="http://docs.marklogic.com/cts:lsqt-query">cts:lsqt-query calls</a>
 * @return a query to filter by lsqt
 * @see <a href="http://docs.marklogic.com/cts:lsqt-query">cts:lsqt-query</a>
 * @see <a href="http://docs.marklogic.com/guide/search-dev/structured-query#id_85930">
 *      Structured Queries: lsqt-query</a>
 */
public StructuredQueryDefinition temporalLsqtQuery(String temporalCollection, Calendar time,
                                                   double weight, String... options)
{
  if ( temporalCollection == null ) throw new IllegalArgumentException("temporalCollection cannot be null");
  return new TemporalLsqtQuery(temporalCollection, DatatypeConverter.printDateTime(time), weight, options);
}
 
Example 20
/**
 * Construct a temporal period for use in {@link #temporalPeriodRange temporalPeriodRange}
 * queries.
 * @param start the start date/time for this period
 * @param end   the end date/time for this period
 * @return a temporal period
 */
public StructuredQueryBuilder.Period period(Calendar start, Calendar end) {
  return new TemporalPeriod(DatatypeConverter.printDateTime(start),
    DatatypeConverter.printDateTime(end));
}