String text = null; if (value instanceof java.sql.Date) text = DateUtil.serializeSqlDate((java.sql.Date) value); else if (value instanceof java.sql.Time) text = DateUtil.serializeSqlTime((java.sql.Time) value); else text = DateUtil.serializeDateTime((Date) value); contentHandler.characters(text.toCharArray(), 0, text.length()); } else {
/** * Deserialize date from general dateTime text. Date values are expected to match W3C XML Schema * standard format as CCYY-MM-DDThh:mm:ss, with optional leading minus sign and trailing seconds * decimal, as necessary. This method follows standard JiBX deserializer usage requirements by * accepting a <code>null</code> input. * * @param text text to be parsed (may be <code>null</code>) * @return converted date, or <code>null</code> if passed <code>null</code> input * @throws IllegalArgumentException on parse error */ public static Date deserializeDateTime(String text) throws IllegalArgumentException { if (text == null) { return null; } else { return new Date(parseDateTime(text)); } }
public void testJavaUtilDate() { Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(2007, 3, 1, 1, 15); Date time = cal.getTime(); String dateTime = DateUtil.serializeDateTime(time); assertEquals("2007-04-01T01:15:00", dateTime); String date = DateUtil.serializeDate(time); assertEquals("2007-04-01", date); }
String value = serializeInt(nano); return serializeDateTime(stamp.getTime(), false) + '.' + digits + 'Z'; } else { return serializeDateTime(stamp.getTime(), true);
nano = parseDigits(text, split + 1, length); Timestamp stamp = new Timestamp(parseDateTime(text)); stamp.setNanos(nano);
/** * Serialize time to general dateTime text. This method is provided for backward compatibility. * It generates the dateTime text without the trailing 'Z' to indicate UTC. * * @param time time to be converted, as milliseconds from January 1, 1970 * @return converted dateTime text * @throws IllegalArgumentException on conversion error */ public static String serializeDateTime(long time) throws IllegalArgumentException { return serializeDateTime(time, false); }
/** * Serialize SQL date to general date text. Date values are formatted in W3C XML Schema standard * format as CCYY-MM-DD, with optional leading sign included if necessary. * * @param date date to be converted * @return converted date text * @throws IllegalArgumentException on conversion error */ public static String serializeSqlDate(java.sql.Date date) throws IllegalArgumentException { return serializeDate(date); }
public void testSqlTime() { Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(2007, 3, 1, 1, 15); long lngTime = cal.getTime().getTime(); java.sql.Time time = new java.sql.Time(lngTime); // System.out.println(time); String t = DateUtil.serializeSqlTime(time); // System.out.println(t); assertEquals("01:15:00", t); } }
public void testSqlDate() { Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(2007, 3, 1, 1, 15); Date time = cal.getTime(); java.sql.Date date = new java.sql.Date(time.getTime()); String dateTime = DateUtil.serializeSqlDate(date); assertEquals("2007-04-01", dateTime); }
d = DateUtil.deserializeDateTime(date); } catch (Exception e1) { try { d = DateUtil.deserializeDate(date); } catch (Exception e2) {
public static Date date(final String dateTimeStr) { Date dateTime = DateUtil.deserializeDateTime(dateTimeStr); return dateTime; }
/** * Serialize date to general dateTime text. Date values are formatted in W3C XML Schema standard * format as CCYY-MM-DDThh:mm:ss, with optional leading sign and trailing seconds decimal, as * necessary. * * @param date date to be converted * @return converted dateTime text * @throws IllegalArgumentException on conversion error */ public static String serializeDateTime(Date date) throws IllegalArgumentException { long time = date.getTime(); time += TimeZone.getDefault().getOffset(time); return serializeDateTime(time, false); }
String value = serializeInt(nano); return serializeDateTime(stamp.getTime(), false) + '.' + digits + 'Z'; } else { return serializeDateTime(stamp.getTime(), true);
nano = parseDigits(text, split + 1, length); Timestamp stamp = new Timestamp(parseDateTime(text)); stamp.setNanos(nano);
/** * Serialize date to general date text. Date values are formatted in W3C XML Schema standard * format as CCYY-MM-DD, with optional leading sign included if necessary. * * @param date date to be converted * @return converted date text * @throws IllegalArgumentException on conversion error */ public static String serializeDate(Date date) throws IllegalArgumentException { long time = date.getTime(); time += TimeZone.getDefault().getOffset(time); return serializeDate(time); }
@Override public String format(Object att) { return prepCSVField(DateUtil.serializeSqlTime((java.sql.Time) att)); } }
@Override public String format(Object att) { return prepCSVField(DateUtil.serializeSqlDate((java.sql.Date) att)); } }
d = DateUtil.deserializeDateTime(date); } catch (Exception e1) { try { d = DateUtil.deserializeDate(date); } catch (Exception e2) {
public static Date date(final String dateTimeStr) { Date dateTime = DateUtil.deserializeDateTime(dateTimeStr); return dateTime; }
private String formatToString(Object att, NumberFormat coordFormatter) { String value; if (att instanceof Number) { // don't allow scientific notation in the output, as OpenOffice won't // recognize that as a number value = coordFormatter.format(att); } else if (att instanceof Date) { // serialize dates in ISO format if (att instanceof java.sql.Date) value = DateUtil.serializeSqlDate((java.sql.Date) att); else if (att instanceof java.sql.Time) value = DateUtil.serializeSqlTime((java.sql.Time) att); else value = DateUtil.serializeDateTime((Date) att); } else { // everything else we just "toString" value = att.toString(); } return value; }