/** * Parses a {@code LocalDateTime} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static LocalDateTime parse(String str, DateTimeFormatter formatter) { return formatter.parseLocalDateTime(str); }
/** * Parses a {@code LocalDateTime} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static LocalDateTime parse(String str, DateTimeFormatter formatter) { return formatter.parseLocalDateTime(str); }
@Override public LocalDateTime parse(String text, Locale locale) throws ParseException { return JodaTimeContextHolder.getFormatter(this.formatter, locale).parseLocalDateTime(text); }
@Override public LocalDateTime parse(String text, Locale locale) throws ParseException { return JodaTimeContextHolder.getFormatter(this.formatter, locale).parseLocalDateTime(text); }
/** * Parse a string (optionally containing a zone) as a value of TIMESTAMP type. * If the string specifies a zone, the zone is discarded. * <p> * For example: {@code "2000-01-01 01:23:00"} is parsed to TIMESTAMP {@code 2000-01-01T01:23:00} * and {@code "2000-01-01 01:23:00 +01:23"} is also parsed to TIMESTAMP {@code 2000-01-01T01:23:00.000}. * * @return stack representation of TIMESTAMP type */ public static long parseTimestampWithoutTimeZone(String value) { LocalDateTime localDateTime = TIMESTAMP_WITH_OR_WITHOUT_TIME_ZONE_FORMATTER.parseLocalDateTime(value); try { return (long) getLocalMillis.invokeExact(localDateTime); } catch (Throwable e) { throw new RuntimeException(e); } }
/** * Parses only the local time from the given text, returning a new LocalTime. * <p> * This will parse the text fully according to the formatter, using the UTC zone. * Once parsed, only the local time will be used. * This means that any parsed date, time-zone or offset field is completely ignored. * It also means that the zone and offset-parsed settings are ignored. * * @param text the text to parse, not null * @return the parsed time, never null * @throws UnsupportedOperationException if parsing is not supported * @throws IllegalArgumentException if the text to parse is invalid * @since 2.0 */ public LocalTime parseLocalTime(String text) { return parseLocalDateTime(text).toLocalTime(); }
/** * Parses only the local date from the given text, returning a new LocalDate. * <p> * This will parse the text fully according to the formatter, using the UTC zone. * Once parsed, only the local date will be used. * This means that any parsed time, time-zone or offset field is completely ignored. * It also means that the zone and offset-parsed settings are ignored. * * @param text the text to parse, not null * @return the parsed date, never null * @throws UnsupportedOperationException if parsing is not supported * @throws IllegalArgumentException if the text to parse is invalid * @since 2.0 */ public LocalDate parseLocalDate(String text) { return parseLocalDateTime(text).toLocalDate(); }
/** * Parses only the local time from the given text, returning a new LocalTime. * <p> * This will parse the text fully according to the formatter, using the UTC zone. * Once parsed, only the local time will be used. * This means that any parsed date, time-zone or offset field is completely ignored. * It also means that the zone and offset-parsed settings are ignored. * * @param text the text to parse, not null * @return the parsed time, never null * @throws UnsupportedOperationException if parsing is not supported * @throws IllegalArgumentException if the text to parse is invalid * @since 2.0 */ public LocalTime parseLocalTime(String text) { return parseLocalDateTime(text).toLocalTime(); }
/** * Parses only the local date from the given text, returning a new LocalDate. * <p> * This will parse the text fully according to the formatter, using the UTC zone. * Once parsed, only the local date will be used. * This means that any parsed time, time-zone or offset field is completely ignored. * It also means that the zone and offset-parsed settings are ignored. * * @param text the text to parse, not null * @return the parsed date, never null * @throws UnsupportedOperationException if parsing is not supported * @throws IllegalArgumentException if the text to parse is invalid * @since 2.0 */ public LocalDate parseLocalDate(String text) { return parseLocalDateTime(text).toLocalDate(); }
private Optional<Timestamp> tryParseWithFormat(String strValue) { checkState(fmt != null); if (startingDateValue != null) { // reset value in case any date fields are missing from the date pattern MutableDateTime mdt = new MutableDateTime( startingDateValue, ISOChronology.getInstanceUTC()); // Using parseInto() avoids throwing exception when parsing, // allowing fallback to default timestamp parsing if custom patterns fail. int ret = fmt.parseInto(mdt, strValue, 0); // Only accept parse results if we parsed the entire string if (ret == strValue.length()) { return Optional.of(Timestamp.ofEpochMilli(mdt.getMillis())); } return Optional.empty(); } try { LocalDateTime dt = fmt.parseLocalDateTime(strValue); return Optional.of( Timestamp.ofEpochMilli( dt.toDateTime(ISOChronology.getInstanceUTC().getZone()).getMillis())); } catch (IllegalArgumentException e) { return Optional.empty(); } }
/** * Parses a {@code LocalDateTime} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static LocalDateTime parse(String str, DateTimeFormatter formatter) { return formatter.parseLocalDateTime(str); }
@Override protected LocalDateTime deserialize(String key, DeserializationContext ctxt) throws IOException { return parser.parseLocalDateTime(key); } }
String pattern = "'wallclock('yyyy-MM-dd'T'HH:mm:ss')'"; DateTimeFormatter formatter = DateTimeFormatter.forPattern(pattern); LocalDateTime localDateTime = formatter.parseLocalDateTime(text);
String input = "2011120312345655"; DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyyMMddHHmmssSS"); System.out.println(dtf.parseLocalDateTime(input)); // 2011-12-03T12:34:56.550
/** * Parses only the local time from the given text, returning a new LocalDate. * <p> * This will parse the text fully according to the formatter, using the UTC zone. * Once parsed, only the local time will be used. * This means that any parsed date, time-zone or offset field is completely ignored. * It also means that the zone and offset-parsed settings are ignored. * * @param text the text to parse, not null * @return the parsed time, never null * @throws UnsupportedOperationException if parsing is not supported * @throws IllegalArgumentException if the text to parse is invalid * @since 2.0 */ public LocalTime parseLocalTime(String text) { return parseLocalDateTime(text).toLocalTime(); }
/** * Parses only the local date from the given text, returning a new LocalDate. * <p> * This will parse the text fully according to the formatter, using the UTC zone. * Once parsed, only the local date will be used. * This means that any parsed time, time-zone or offset field is completely ignored. * It also means that the zone and offset-parsed settings are ignored. * * @param text the text to parse, not null * @return the parsed date, never null * @throws UnsupportedOperationException if parsing is not supported * @throws IllegalArgumentException if the text to parse is invalid * @since 2.0 */ public LocalDate parseLocalDate(String text) { return parseLocalDateTime(text).toLocalDate(); }
: _format.createParser(ctxt).parseLocalDateTime(str);
static LocalDateTime deserialize(String serializedValue) { if (serializedValue == null) { return null; } if (serializedValue.length() == 19) { return deserialize(serializedValue + ".0"); } return ISO_DATE_TIME_FORMATTER.parseLocalDateTime(serializedValue); }
@Override public void writeTime(boolean isNull) throws IOException { TimeMilliWriter t = writer.timeMilli(); if(!isNull){ DateTimeFormatter f = ISODateTimeFormat.time(); t.writeTimeMilli((int) com.dremio.common.util.DateTimes.toMillis(f.parseLocalDateTime(parser.getValueAsString()))); } }
@Test public void testTimestamp() throws Exception { String sql = String.format("select datefield from elasticsearch.%s.%s where datefield < timestamp '2014-02-12 00:00:00'", schema, table); testBuilder() .sqlQuery(sql) .unOrdered() .baselineColumns("datefield") .baselineValues(formatter.parseLocalDateTime("2014-02-10 10:50:42")) .baselineValues(formatter.parseLocalDateTime("2014-02-11 10:50:42")) .baselineValues(formatter.parseLocalDateTime("2014-02-10 10:50:42")) .go(); }