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

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

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

LocalDateTime.of介绍

[英]Obtains an instance of LocalDateTime from year, month, day, hour and minute, setting the second and nanosecond to zero.

The day must be valid for the year and month, otherwise an exception will be thrown. The second and nanosecond fields will be set to zero.
[中]从年、月、日、小时和分钟获取LocalDateTime的实例,将秒和纳秒设置为零。
日期必须对年和月有效,否则将引发异常。第二个和纳秒字段将设置为零。

代码示例

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

/**
 * Combines this time with a date to create a {@code LocalDateTime}.
 * <p>
 * This returns a {@code LocalDateTime} formed from this time at the specified date.
 * All possible combinations of date and time are valid.
 *
 * @param date  the date to combine with, not null
 * @return the local date-time formed from this time and the specified date, not null
 */
public LocalDateTime atDate(LocalDate date) {
  return LocalDateTime.of(date, this);
}

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

/**
 * Combines this date with the time of midnight to create a {@code LocalDateTime}
 * at the start of this date.
 * <p>
 * This returns a {@code LocalDateTime} formed from this date at the time of
 * midnight, 00:00, at the start of this date.
 *
 * @return the local date-time of midnight at the start of this date, not null
 */
public LocalDateTime atStartOfDay() {
  return LocalDateTime.of(this, LocalTime.MIDNIGHT);
}

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

/**
 * Combines this time with a date to create a {@code LocalDateTime}.
 * <p>
 * This returns a {@code LocalDateTime} formed from this time at the specified date.
 * All possible combinations of date and time are valid.
 *
 * @param date  the date to combine with, not null
 * @return the local date-time formed from this time and the specified date, not null
 */
public LocalDateTime atDate(LocalDate date) {
  return LocalDateTime.of(date, this);
}

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

/**
 * Combines this date with the time of midnight to create a {@code LocalDateTime}
 * at the start of this date.
 * <p>
 * This returns a {@code LocalDateTime} formed from this date at the time of
 * midnight, 00:00, at the start of this date.
 *
 * @return the local date-time of midnight at the start of this date, not null
 */
public LocalDateTime atStartOfDay() {
  return LocalDateTime.of(this, LocalTime.MIDNIGHT);
}

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

/**
 * Combines this date with a time to create a {@code LocalDateTime}.
 * <p>
 * This returns a {@code LocalDateTime} formed from this date at the specified time.
 * All possible combinations of date and time are valid.
 *
 * @param time  the time to combine with, not null
 * @return the local date-time formed from this date and the specified time, not null
 */
@Override
public LocalDateTime atTime(LocalTime time) {
  return LocalDateTime.of(this, time);
}

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

/**
 * Combines this date with a time to create a {@code LocalDateTime}.
 * <p>
 * This returns a {@code LocalDateTime} formed from this date at the specified time.
 * All possible combinations of date and time are valid.
 *
 * @param time  the time to combine with, not null
 * @return the local date-time formed from this date and the specified time, not null
 */
@Override
public LocalDateTime atTime(LocalTime time) {
  return LocalDateTime.of(this, time);
}

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

/**
 * Obtains an instance of {@code OffsetDateTime} from a date, time and offset.
 * <p>
 * This creates an offset date-time with the specified local date, time and offset.
 *
 * @param date  the local date, not null
 * @param time  the local time, not null
 * @param offset  the zone offset, not null
 * @return the offset date-time, not null
 */
public static OffsetDateTime of(LocalDate date, LocalTime time, ZoneOffset offset) {
  LocalDateTime dt = LocalDateTime.of(date, time);
  return new OffsetDateTime(dt, offset);
}

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

/**
 * Obtains an instance of {@code OffsetDateTime} from a date, time and offset.
 * <p>
 * This creates an offset date-time with the specified local date, time and offset.
 *
 * @param date  the local date, not null
 * @param time  the local time, not null
 * @param offset  the zone offset, not null
 * @return the offset date-time, not null
 */
public static OffsetDateTime of(LocalDate date, LocalTime time, ZoneOffset offset) {
  LocalDateTime dt = LocalDateTime.of(date, time);
  return new OffsetDateTime(dt, offset);
}

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

static LocalDateTime readExternal(DataInput in) throws IOException {
  LocalDate date = LocalDate.readExternal(in);
  LocalTime time = LocalTime.readExternal(in);
  return LocalDateTime.of(date, time);
}

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

static LocalDateTime readExternal(DataInput in) throws IOException {
  LocalDate date = LocalDate.readExternal(in);
  LocalTime time = LocalTime.readExternal(in);
  return LocalDateTime.of(date, time);
}

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

/**
 * Combines this date with an offset time to create an {@code OffsetDateTime}.
 * <p>
 * This returns an {@code OffsetDateTime} formed from this date at the specified time.
 * All possible combinations of date and time are valid.
 *
 * @param time  the time to combine with, not null
 * @return the offset date-time formed from this date and the specified time, not null
 */
public OffsetDateTime atTime(OffsetTime time) {
  return OffsetDateTime.of(LocalDateTime.of(this, time.toLocalTime()), time.getOffset());
}

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

/**
 * Combines this date with an offset time to create an {@code OffsetDateTime}.
 * <p>
 * This returns an {@code OffsetDateTime} formed from this date at the specified time.
 * All possible combinations of date and time are valid.
 *
 * @param time  the time to combine with, not null
 * @return the offset date-time formed from this date and the specified time, not null
 */
public OffsetDateTime atTime(OffsetTime time) {
  return OffsetDateTime.of(LocalDateTime.of(this, time.toLocalTime()), time.getOffset());
}

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

@Before
public void setUp() throws Exception {
  jsr301DateTime = LocalDateTime.of(1970, Month.MAY, 18, 13, 30, 0, 20000000);
  jsr301Date = LocalDate.of(1970, Month.MAY, 18);
  jsr301Time = LocalTime.of(13, 30, 0);
  jodaDateTime = new DateTime(1970, 5, 18, 13, 30, 0, 20);
  jodaDateTimeUtc = new DateTime(1970, 5, 18, 13, 30, 0, 20, DateTimeZone.UTC);
}

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

/**
 * Converts a {@code java.sql.Timestamp} to a {@code LocalDateTime}.
 *
 * @param sqlTimestamp  the SQL timestamp, not null
 * @return the local date-time, not null
 */
@SuppressWarnings("deprecation")
public static LocalDateTime toLocalDateTime(Timestamp sqlTimestamp) {
  return LocalDateTime.of(
      sqlTimestamp.getYear() + 1900,
      sqlTimestamp.getMonth() + 1,
      sqlTimestamp.getDate(),
      sqlTimestamp.getHours(),
      sqlTimestamp.getMinutes(),
      sqlTimestamp.getSeconds(),
      sqlTimestamp.getNanos());
}

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

/**
 * Converts a {@code java.sql.Timestamp} to a {@code LocalDateTime}.
 *
 * @param sqlTimestamp  the SQL timestamp, not null
 * @return the local date-time, not null
 */
@SuppressWarnings("deprecation")
public static LocalDateTime toLocalDateTime(Timestamp sqlTimestamp) {
  return LocalDateTime.of(
      sqlTimestamp.getYear() + 1900,
      sqlTimestamp.getMonth() + 1,
      sqlTimestamp.getDate(),
      sqlTimestamp.getHours(),
      sqlTimestamp.getMinutes(),
      sqlTimestamp.getSeconds(),
      sqlTimestamp.getNanos());
}

代码示例来源: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));
  }
}

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

private LocalDateTime toDateTime(int year) {
    adjustToFowards(year);
    LocalDate date;
    if (dayOfMonth == -1) {
      dayOfMonth = month.length(Year.isLeap(year));
      date = LocalDate.of(year, month, dayOfMonth);
      if (dayOfWeek != null) {
        date = date.with(TemporalAdjusters.previousOrSame(dayOfWeek));
      }
    } else {
      date = LocalDate.of(year, month, dayOfMonth);
      if (dayOfWeek != null) {
        date = date.with(TemporalAdjusters.nextOrSame(dayOfWeek));
      }
    }
    date = deduplicate(date.plusDays(adjustDays));
    return LocalDateTime.of(date, time);
  }
}

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

private LocalDateTime toDateTime(int year) {
    adjustToFowards(year);
    LocalDate date;
    if (dayOfMonth == -1) {
      dayOfMonth = month.length(Year.isLeap(year));
      date = LocalDate.of(year, month, dayOfMonth);
      if (dayOfWeek != null) {
        date = date.with(TemporalAdjusters.previousOrSame(dayOfWeek));
      }
    } else {
      date = LocalDate.of(year, month, dayOfMonth);
      if (dayOfWeek != null) {
        date = date.with(TemporalAdjusters.nextOrSame(dayOfWeek));
      }
    }
    date = deduplicate(date.plusDays(adjustDays));
    return LocalDateTime.of(date, time);
  }
}

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

/**
 * Converts this to a transition.
 *
 * @param standardOffset  the active standard offset, not null
 * @param savingsBeforeSecs  the active savings in seconds
 * @return the transition, not null
 */
ZoneOffsetTransition toTransition(ZoneOffset standardOffset, int savingsBeforeSecs) {
  // copy of code in ZoneOffsetTransitionRule to avoid infinite loop
  LocalDate date = toLocalDate();
  date = deduplicate(date);
  LocalDateTime ldt = deduplicate(LocalDateTime.of(date.plusDays(adjustDays), time));
  ZoneOffset wallOffset = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingsBeforeSecs));
  LocalDateTime dt = deduplicate(timeDefinition.createDateTime(ldt, standardOffset, wallOffset));
  ZoneOffset offsetAfter = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingAmountSecs));
  return new ZoneOffsetTransition(dt, wallOffset, offsetAfter);
}

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

/**
 * Converts this to a transition.
 *
 * @param standardOffset  the active standard offset, not null
 * @param savingsBeforeSecs  the active savings in seconds
 * @return the transition, not null
 */
ZoneOffsetTransition toTransition(ZoneOffset standardOffset, int savingsBeforeSecs) {
  // copy of code in ZoneOffsetTransitionRule to avoid infinite loop
  LocalDate date = toLocalDate();
  date = deduplicate(date);
  LocalDateTime ldt = deduplicate(LocalDateTime.of(date.plusDays(adjustDays), time));
  ZoneOffset wallOffset = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingsBeforeSecs));
  LocalDateTime dt = deduplicate(timeDefinition.createDateTime(ldt, standardOffset, wallOffset));
  ZoneOffset offsetAfter = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingAmountSecs));
  return new ZoneOffsetTransition(dt, wallOffset, offsetAfter);
}

相关文章