@Test public void testParseTimestamp_WithNanos() { assertEquals(123000000, DateUtil.parseTimestamp("1970-01-01 00:00:10.123").getNanos()); assertEquals(123456780, DateUtil.parseTimestamp("1970-01-01 00:00:10.12345678").getNanos ()); assertEquals(999999999, DateUtil.parseTimestamp("1970-01-01 00:00:10.999999999").getNanos ()); }
public static Timestamp parseTimestamp(String timestampValue) { Timestamp timestamp = new Timestamp(parseDateTime(timestampValue)); int period = timestampValue.indexOf('.'); if (period > 0) { String nanosStr = timestampValue.substring(period + 1); if (nanosStr.length() > 9) throw new IllegalDataException("nanos > 999999999 or < 0"); if(nanosStr.length() > 3 ) { int nanos = Integer.parseInt(nanosStr); for (int i = 0; i < 9 - nanosStr.length(); i++) { nanos *= 10; } timestamp.setNanos(nanos); } } return timestamp; }
DateUtil { public static Timestamp parseTimestamp(String timestampValue) { Timestamp timestamp = new Timestamp(parseDateTime(timestampValue)); int period = timestampValue.indexOf('.'); if (period > 0) { String nanosStr = timestampValue.substring(period + 1); if (nanosStr.length() > 9) throw new IllegalDataException("nanos > 999999999 or < 0"); if(nanosStr.length() > 3 ) { int nanos = Integer.parseInt(nanosStr); for (int i = 0; i < 9 - nanosStr.length(); i++) { nanos *= 10; } timestamp.setNanos(nanos); } } return timestamp; } }
DateUtil { public static Timestamp parseTimestamp(String timestampValue) { Timestamp timestamp = new Timestamp(parseDateTime(timestampValue)); int period = timestampValue.indexOf('.'); if (period > 0) { String nanosStr = timestampValue.substring(period + 1); if (nanosStr.length() > 9) throw new IllegalDataException("nanos > 999999999 or < 0"); if(nanosStr.length() > 3 ) { int nanos = Integer.parseInt(nanosStr); for (int i = 0; i < 9 - nanosStr.length(); i++) { nanos *= 10; } timestamp.setNanos(nanos); } } return timestamp; } private  DateUtil(); }
DateUtil { public static Timestamp parseTimestamp(String timestampValue) { Timestamp timestamp = new Timestamp(parseDateTime(timestampValue)); int period = timestampValue.indexOf('.'); if (period > 0) { String nanosStr = timestampValue.substring(period + 1); if (nanosStr.length() > 9) throw new IllegalDataException("nanos > 999999999 or < 0"); if(nanosStr.length() > 3 ) { int nanos = Integer.parseInt(nanosStr); for (int i = 0; i < 9 - nanosStr.length(); i++) { nanos *= 10; } timestamp.setNanos(nanos); } } return timestamp; } private  DateUtil(); @NonNull static PDataCodec getCodecFor(PDataType type); static TimeZone getTimeZone(String timeZoneId); static DateTimeParser getDateTimeParser(String pattern, PDataType pDataType, String timeZoneId); static DateTimeParser getDateTimeParser(String pattern, PDataType pDataType); static Format getDateFormatter(String pattern); static Format getDateFormatter(String pattern, String timeZoneID); static Format getTimeFormatter(String pattern, String timeZoneID); static Format getTimestampFormatter(String pattern, String timeZoneID); static Date parseDate(String dateValue); static Time parseTime(String timeValue); static Timestamp parseTimestamp(String timestampValue); static Timestamp getTimestamp(long millis, int nanos); static Timestamp getTimestamp(BigDecimal bd); }
DateUtil { public static Timestamp parseTimestamp(String timestampValue) { Timestamp timestamp = new Timestamp(parseDateTime(timestampValue)); int period = timestampValue.indexOf('.'); if (period > 0) { String nanosStr = timestampValue.substring(period + 1); if (nanosStr.length() > 9) throw new IllegalDataException("nanos > 999999999 or < 0"); if(nanosStr.length() > 3 ) { int nanos = Integer.parseInt(nanosStr); for (int i = 0; i < 9 - nanosStr.length(); i++) { nanos *= 10; } timestamp.setNanos(nanos); } } return timestamp; } private  DateUtil(); @NonNull static PDataCodec getCodecFor(PDataType type); static TimeZone getTimeZone(String timeZoneId); static DateTimeParser getDateTimeParser(String pattern, PDataType pDataType, String timeZoneId); static DateTimeParser getDateTimeParser(String pattern, PDataType pDataType); static Format getDateFormatter(String pattern); static Format getDateFormatter(String pattern, String timeZoneID); static Format getTimeFormatter(String pattern, String timeZoneID); static Format getTimestampFormatter(String pattern, String timeZoneID); static Date parseDate(String dateValue); static Time parseTime(String timeValue); static Timestamp parseTimestamp(String timestampValue); static Timestamp getTimestamp(long millis, int nanos); static Timestamp getTimestamp(BigDecimal bd); static final String DEFAULT_TIME_ZONE_ID; static final String LOCAL_TIME_ZONE_ID; static final String DEFAULT_MS_DATE_FORMAT; static final Format DEFAULT_MS_DATE_FORMATTER; static final String DEFAULT_DATE_FORMAT; static final Format DEFAULT_DATE_FORMATTER; static final String DEFAULT_TIME_FORMAT; static final Format DEFAULT_TIME_FORMATTER; static final String DEFAULT_TIMESTAMP_FORMAT; static final Format DEFAULT_TIMESTAMP_FORMATTER; }