org.threeten.bp.LocalDateTime.parse()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(3.6k)|赞(0)|评价(0)|浏览(188)

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

LocalDateTime.parse介绍

[英]Obtains an instance of LocalDateTime from a text string such as 2007-12-23T10:15:30.

The string must represent a valid date-time and is parsed using org.threeten.bp.format.DateTimeFormatter#ISO_LOCAL_DATE_TIME.
[中]从文本字符串(如2007-12-23T10:15:30)获取LocalDateTime的实例。
字符串必须表示有效的日期和时间,并使用org进行解析。三十。英国石油公司。总体安排DateTimeFormatter#ISO(本地)日期(时间)。

代码示例

代码示例来源:origin: ThreeTen/threetenbp

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

代码示例来源:origin: org.threeten/threetenbp

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

代码示例来源:origin: jeffdcamp/dbtools-android

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

代码示例来源:origin: com.github.joschi.jackson/jackson-datatype-threetenbp

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

代码示例来源:origin: guanpj/JReadHub

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

代码示例来源:origin: ngs-doo/dsl-json

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

相关文章