/** * Obtains an instance of {@code LocalDateTime} from a text string such as {@code 2007-12-23T10:15:30}. * <p> * The string must represent a valid date-time and is parsed using * {@link org.threeten.bp.format.DateTimeFormatter#ISO_LOCAL_DATE_TIME}. * * @param text the text to parse such as "2007-12-23T10:15:30", not null * @return the parsed local date-time, not null * @throws DateTimeParseException if the text cannot be parsed */ public static LocalDateTime parse(CharSequence text) { return parse(text, DateTimeFormatter.ISO_LOCAL_DATE_TIME); }
/** * Obtains an instance of {@code LocalDateTime} from a text string such as {@code 2007-12-03T10:15:30}. * <p> * The string must represent a valid date-time and is parsed using * {@link org.threeten.bp.format.DateTimeFormatter#ISO_LOCAL_DATE_TIME}. * * @param text the text to parse such as "2007-12-03T10:15:30", not null * @return the parsed local date-time, not null * @throws DateTimeParseException if the text cannot be parsed */ public static LocalDateTime parse(CharSequence text) { return parse(text, DateTimeFormatter.ISO_LOCAL_DATE_TIME); }
@Nullable public static LocalDateTime dbStringToLocalDateTime(@Nullable String text) { if (text != null && text.length() > 0 && !text.equals("null")) { try { return LocalDateTime.parse(text, DB_DATETIME_FORMATTER310); } catch (Exception ex) { throw new IllegalArgumentException("Cannot parse date time text: " + text, ex); } } else { return null; } }
@Override protected LocalDateTime deserialize(String key, DeserializationContext ctxt) throws IOException { try { return LocalDateTime.parse(key, DateTimeFormatter.ISO_LOCAL_DATE_TIME); } catch (DateTimeException e) { return _rethrowDateTimeException(ctxt, LocalDateTime.class, e, key); } }
public static OffsetDateTime string2ODT(String timeStr) { if (!TextUtils.isEmpty(timeStr)) { DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); LocalDateTime localDateTime = LocalDateTime.parse(timeStr, df); return OffsetDateTime.of(localDateTime, ZoneOffset.UTC); } return null; } }
public static LocalDateTime deserializeLocalDateTime(final JsonReader reader) throws IOException { final char[] tmp = reader.readSimpleQuote(); final int len = reader.getCurrentIndex() - reader.getTokenStart() - 1; if (len > 18 && len < 30 && tmp[4] == '-' && tmp[7] == '-' && (tmp[10] == 'T' || tmp[10] == 't' || tmp[10] == ' ') && tmp[13] == ':' && tmp[16] == ':' && allDigits(tmp, 20, len)) { final int year = NumberConverter.read4(tmp, 0); final int month = NumberConverter.read2(tmp, 5); final int day = NumberConverter.read2(tmp, 8); final int hour = NumberConverter.read2(tmp, 11); final int min = NumberConverter.read2(tmp, 14); final int sec = NumberConverter.read2(tmp, 17); if (len > 19 && tmp[19] == '.') { final int nanos = readNanos(tmp, len); return LocalDateTime.of(year, month, day, hour, min, sec, nanos); } return LocalDateTime.of(year, month, day, hour, min, sec); } else { return LocalDateTime.parse(new String(tmp, 0, len)); } }