Java Code Examples for javax.xml.bind.DatatypeConverter#printDateTime()
The following examples show how to use
javax.xml.bind.DatatypeConverter#printDateTime() .
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
Source File: CloverDateTimeConvertor.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
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 2
Source File: StructuredQueryBuilder.java From java-client-api with Apache License 2.0 | 6 votes |
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 File: CejshBuilder.java From proarc with GNU General Public License v3.0 | 6 votes |
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 4
Source File: XmlDateTimeTypeAdapter.java From cia with Apache License 2.0 | 5 votes |
@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 5
Source File: SearchHandler.java From olingo-odata4 with Apache License 2.0 | 5 votes |
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 6
Source File: IQEntityTimeHandler.java From Openfire with Apache License 2.0 | 5 votes |
/** * 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 7
Source File: DataTypeAdapter.java From govpay with GNU General Public License v3.0 | 5 votes |
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 8
Source File: DataTypeAdapterCXF.java From govpay with GNU General Public License v3.0 | 5 votes |
public static String printDateTime(Date dt) { if (dt == null) { return null; } Calendar c = Calendar.getInstance(); c.setTime(dt); return DatatypeConverter.printDateTime(c); }
Example 9
Source File: DataTypeAdapter.java From govpay with GNU General Public License v3.0 | 5 votes |
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 10
Source File: DataTypeAdapterCXF.java From govpay with GNU General Public License v3.0 | 5 votes |
public static String printDateTime(Date dt) { if (dt == null) { return null; } Calendar c = Calendar.getInstance(); c.setTime(dt); return DatatypeConverter.printDateTime(c); }
Example 11
Source File: PigUtils.java From elasticsearch-hadoop with Apache License 2.0 | 5 votes |
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 12
Source File: BaseEventConverter.java From elasticsearch-hadoop with Apache License 2.0 | 5 votes |
/** * Visible for testing */ public String getTimestamp(E event) { long millis = System.currentTimeMillis(); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(millis); return DatatypeConverter.printDateTime(cal); }
Example 13
Source File: ImmobiliareItUtils.java From OpenEstate-IO with Apache License 2.0 | 4 votes |
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 14
Source File: DateTimeToDateAdapter.java From xmlunit with Apache License 2.0 | 4 votes |
@Override public String marshal(final Date value) { final Calendar cal = new GregorianCalendar(); cal.setTime(value); return DatatypeConverter.printDateTime(cal); }
Example 15
Source File: ImmoXmlUtils.java From OpenEstate-IO with Apache License 2.0 | 4 votes |
public static String printDateTime(Calendar value) { if (value == null) throw new IllegalArgumentException("Can't print date-time value!"); else return DatatypeConverter.printDateTime(value); }
Example 16
Source File: DateUtils.java From freehealth-connector with GNU Affero General Public License v3.0 | 4 votes |
public static String printDateTime(DateTime dateTime) { return dateTime == null ? null : DatatypeConverter.printDateTime(convert(dateTime)); }
Example 17
Source File: DateUtils.java From freehealth-connector with GNU Affero General Public License v3.0 | 4 votes |
public static String printDateTime(DateTime dateTime) { return dateTime == null ? null : DatatypeConverter.printDateTime(convert(dateTime)); }
Example 18
Source File: CalendarConverter.java From vraptor4 with Apache License 2.0 | 4 votes |
@Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { String out = DatatypeConverter.printDateTime((Calendar) source); writer.setValue(out); }
Example 19
Source File: StructuredQueryBuilder.java From java-client-api with Apache License 2.0 | 3 votes |
/** * 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
Source File: StructuredQueryBuilder.java From java-client-api with Apache License 2.0 | 2 votes |
/** * 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)); }