/** * Convert a timestamp string into a LocalDateTime object. * LocalDateTime has up to nanosecond precision. * * @param value the timestamp String * @return the parsed timestamp * @exception FieldConvertError raised if timestamp is an incorrect format. */ public static LocalDateTime convertToLocalDateTime(String value) throws FieldConvertError { verifyFormat(value); int length = value.length(); try { switch (length) { case LENGTH_INCL_SECONDS: return LocalDateTime.parse(value, FORMATTER_SECONDS); case LENGTH_INCL_MILLIS: return LocalDateTime.parse(value, FORMATTER_MILLIS); case LENGTH_INCL_MICROS: return LocalDateTime.parse(value, FORMATTER_MICROS); case LENGTH_INCL_NANOS: case LENGTH_INCL_PICOS: return LocalDateTime.parse(value.substring(0, LENGTH_INCL_NANOS), FORMATTER_NANOS); default: throwFieldConvertError(value, TYPE); } } catch (DateTimeParseException e) { throwFieldConvertError(value, TYPE); } return null; }
/** * Convert a timestamp string into a LocalDateTime object. * LocalDateTime has up to nanosecond precision. * * @param value the timestamp String * @return the parsed timestamp * @exception FieldConvertError raised if timestamp is an incorrect format. */ public static LocalDateTime convertToLocalDateTime(String value) throws FieldConvertError { verifyFormat(value); int length = value.length(); try { switch (length) { case LENGTH_INCL_SECONDS: return LocalDateTime.parse(value, FORMATTER_SECONDS); case LENGTH_INCL_MILLIS: return LocalDateTime.parse(value, FORMATTER_MILLIS); case LENGTH_INCL_MICROS: return LocalDateTime.parse(value, FORMATTER_MICROS); case LENGTH_INCL_NANOS: case LENGTH_INCL_PICOS: return LocalDateTime.parse(value.substring(0, LENGTH_INCL_NANOS), FORMATTER_NANOS); default: throwFieldConvertError(value, TYPE); } } catch (DateTimeParseException e) { throwFieldConvertError(value, TYPE); } return null; }
/** * Convert a timestamp string into a Date. * Date has up to millisecond precision. * * @param value the timestamp String * @return the parsed timestamp * @exception FieldConvertError raised if timestamp is an incorrect format. */ public static Date convert(String value) throws FieldConvertError { verifyFormat(value); long timeOffset = getTimeOffsetSeconds(value); if (value.length() >= LENGTH_INCL_MILLIS) { // format has already been verified // accept up to picosenconds but parse only up to milliseconds timeOffset += parseLong(value.substring(18, LENGTH_INCL_MILLIS)); } return new Date(getMillisForDay(value) + timeOffset); }
/** * Convert a timestamp string into a Date. * * @param value the timestamp String * @return the parsed timestamp * @exception FieldConvertError raised if timestamp is an incorrect format. */ public static Date convert(String value) throws FieldConvertError { verifyFormat(value); long timeOffset = (parseLong(value.substring(9, 11)) * 3600000L) + (parseLong(value.substring(12, 14)) * 60000L) + (parseLong(value.substring(15, LENGTH_INCL_SECONDS)) * 1000L); if (value.length() == LENGTH_INCL_MILLIS || value.length() == LENGTH_INCL_MICROS || value.length() == LENGTH_INCL_NANOS || value.length() == LENGTH_INCL_PICOS) { // accept up to picosenconds but parse only up to milliseconds timeOffset += parseLong(value.substring(18, LENGTH_INCL_MILLIS)); } return new Date(getMillisForDay(value) + timeOffset); }
/** * Convert a timestamp string into a Date. * Date has up to millisecond precision. * * @param value the timestamp String * @return the parsed timestamp * @exception FieldConvertError raised if timestamp is an incorrect format. */ public static Date convert(String value) throws FieldConvertError { verifyFormat(value); long timeOffset = getTimeOffsetSeconds(value); if (value.length() >= LENGTH_INCL_MILLIS) { // format has already been verified // accept up to picosenconds but parse only up to milliseconds timeOffset += parseLong(value.substring(18, LENGTH_INCL_MILLIS)); } return new Date(getMillisForDay(value) + timeOffset); }