gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-14 17:28:49 26 4
gpt4 key购买 nike

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

ZonedDateTime.toLocalDateTime介绍

[英]Gets the LocalDateTime part of this date-time.

This returns a LocalDateTime with the same year, month, day and time as this date-time.
[中]获取此日期时间的LocalDateTime部分。
这将返回一个LocalDateTime,其年、月、日和时间与此日期时间相同。

代码示例

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

@Nullable
public static LocalDateTime longToLocalDateTimeUtc(@Nullable Long l) {
  if (l == null) {
    return null;
  }
  return Instant.ofEpochMilli(l).atZone(ZoneOffset.UTC).toLocalDateTime();
}

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

@Nullable
public static LocalDateTime longToLocalDateTime(@Nullable Long l) {
  if (l == null) {
    return null;
  }
  return Instant.ofEpochMilli(l).atZone(ZoneId.systemDefault()).toLocalDateTime();
}

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

/**
 * Obtains an instance of {@code LocalDateTime} from a temporal object.
 * <p>
 * A {@code TemporalAccessor} represents some form of date and time information.
 * This factory converts the arbitrary temporal object to an instance of {@code LocalDateTime}.
 * <p>
 * The conversion extracts and combines {@code LocalDate} and {@code LocalTime}.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code LocalDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the local date-time, not null
 * @throws DateTimeException if unable to convert to a {@code LocalDateTime}
 */
public static LocalDateTime from(TemporalAccessor temporal) {
  if (temporal instanceof LocalDateTime) {
    return (LocalDateTime) temporal;
  } else if (temporal instanceof ZonedDateTime) {
    return ((ZonedDateTime) temporal).toLocalDateTime();
  }
  try {
    LocalDate date = LocalDate.from(temporal);
    LocalTime time = LocalTime.from(temporal);
    return new LocalDateTime(date, time);
  } catch (DateTimeException ex) {
    throw new DateTimeException("Unable to obtain LocalDateTime from TemporalAccessor: " +
        temporal + ", type " + temporal.getClass().getName());
  }
}

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

/**
 * Obtains an instance of {@code LocalDateTime} from a temporal object.
 * <p>
 * A {@code TemporalAccessor} represents some form of date and time information.
 * This factory converts the arbitrary temporal object to an instance of {@code LocalDateTime}.
 * <p>
 * The conversion extracts and combines {@code LocalDate} and {@code LocalTime}.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code LocalDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the local date-time, not null
 * @throws DateTimeException if unable to convert to a {@code LocalDateTime}
 */
public static LocalDateTime from(TemporalAccessor temporal) {
  if (temporal instanceof LocalDateTime) {
    return (LocalDateTime) temporal;
  } else if (temporal instanceof ZonedDateTime) {
    return ((ZonedDateTime) temporal).toLocalDateTime();
  }
  try {
    LocalDate date = LocalDate.from(temporal);
    LocalTime time = LocalTime.from(temporal);
    return new LocalDateTime(date, time);
  } catch (DateTimeException ex) {
    throw new DateTimeException("Unable to obtain LocalDateTime from TemporalAccessor: " +
        temporal + ", type " + temporal.getClass().getName());
  }
}

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

/**
 * Returns a copy of this date-time changing the zone offset to the
 * later of the two valid offsets at a local time-line overlap.
 * <p>
 * This method only has any effect when the local time-line overlaps, such as
 * at an autumn daylight savings cutover. In this scenario, there are two
 * valid offsets for the local date-time. Calling this method will return
 * a zoned date-time with the later of the two selected.
 * <p>
 * If this method is called when it is not an overlap, {@code this}
 * is returned.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @return a {@code ZonedDateTime} based on this date-time with the later offset, not null
 */
@Override
public ZonedDateTime withLaterOffsetAtOverlap() {
  ZoneOffsetTransition trans = getZone().getRules().getTransition(toLocalDateTime());
  if (trans != null) {
    ZoneOffset laterOffset = trans.getOffsetAfter();
    if (laterOffset.equals(offset) == false) {
      return new ZonedDateTime(dateTime, laterOffset, zone);
    }
  }
  return this;
}

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

/**
 * Returns a copy of this date-time changing the zone offset to the
 * later of the two valid offsets at a local time-line overlap.
 * <p>
 * This method only has any effect when the local time-line overlaps, such as
 * at an autumn daylight savings cutover. In this scenario, there are two
 * valid offsets for the local date-time. Calling this method will return
 * a zoned date-time with the later of the two selected.
 * <p>
 * If this method is called when it is not an overlap, {@code this}
 * is returned.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @return a {@code ZonedDateTime} based on this date-time with the later offset, not null
 */
@Override
public ZonedDateTime withLaterOffsetAtOverlap() {
  ZoneOffsetTransition trans = getZone().getRules().getTransition(toLocalDateTime());
  if (trans != null) {
    ZoneOffset laterOffset = trans.getOffsetAfter();
    if (laterOffset.equals(offset) == false) {
      return new ZonedDateTime(dateTime, laterOffset, zone);
    }
  }
  return this;
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com