org.joda.time.format.DateTimeFormatter.parseLocalDateTime()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(237)

本文整理了Java中org.joda.time.format.DateTimeFormatter.parseLocalDateTime()方法的一些代码示例,展示了DateTimeFormatter.parseLocalDateTime()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTimeFormatter.parseLocalDateTime()方法的具体详情如下:
包路径:org.joda.time.format.DateTimeFormatter
类名称:DateTimeFormatter
方法名:parseLocalDateTime

DateTimeFormatter.parseLocalDateTime介绍

[英]Parses only the local date-time from the given text, returning a new LocalDate.

This will parse the text fully according to the formatter, using the UTC zone. Once parsed, only the local date-time will be used. This means that any parsed time-zone or offset field is completely ignored. It also means that the zone and offset-parsed settings are ignored.
[中]仅解析给定文本中的本地日期时间,返回新的LocalDate。
这将使用UTC区域完全根据格式化程序解析文本。解析后,将仅使用本地日期时间。这意味着任何解析的时区或偏移量字段都将被完全忽略。这还意味着忽略区域和偏移量解析设置。

代码示例

代码示例来源:origin: joda-time/joda-time

/**
 * 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);
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * 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);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public LocalDateTime parse(String text, Locale locale) throws ParseException {
  return JodaTimeContextHolder.getFormatter(this.formatter, locale).parseLocalDateTime(text);
}

代码示例来源:origin: org.springframework/spring-context

@Override
public LocalDateTime parse(String text, Locale locale) throws ParseException {
  return JodaTimeContextHolder.getFormatter(this.formatter, locale).parseLocalDateTime(text);
}

代码示例来源:origin: prestodb/presto

/**
 * 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);
  }
}

代码示例来源:origin: joda-time/joda-time

/**
 * 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();
}

代码示例来源:origin: joda-time/joda-time

/**
 * 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();
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * 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();
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * 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();
}

代码示例来源:origin: apache/hive

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();
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * 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);
}

代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-joda

@Override
  protected LocalDateTime deserialize(String key, DeserializationContext ctxt) throws IOException {
    return parser.parseLocalDateTime(key);
  }
}

代码示例来源:origin: stackoverflow.com

String pattern = "'wallclock('yyyy-MM-dd'T'HH:mm:ss')'";
DateTimeFormatter formatter = DateTimeFormatter.forPattern(pattern);
LocalDateTime localDateTime = formatter.parseLocalDateTime(text);

代码示例来源:origin: stackoverflow.com

String input = "2011120312345655"; 
DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyyMMddHHmmssSS");
System.out.println(dtf.parseLocalDateTime(input)); // 2011-12-03T12:34:56.550

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * 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();
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * 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();
}

代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-joda

: _format.createParser(ctxt).parseLocalDateTime(str);

代码示例来源:origin: javers/javers

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);
}

代码示例来源:origin: dremio/dremio-oss

@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())));
 }
}

代码示例来源:origin: dremio/dremio-oss

@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();
}

相关文章