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

x33g5p2x  于2022-02-05 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(140)

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

ZonedDateTime.of介绍

[英]Obtains an instance of ZonedDateTime from a year, month, day, hour, minute, second, nanosecond and time-zone.

This creates a zoned date-time matching the local date-time of the seven specified fields as closely as possible. Time-zone rules, such as daylight savings, mean that not every local date-time is valid for the specified zone, thus the local date-time may be adjusted.

The local date-time is resolved to a single instant on the time-line. This is achieved by finding a valid offset from UTC/Greenwich for the local date-time as defined by the ZoneRules of the zone ID.

In most cases, there is only one valid offset for a local date-time. In the case of an overlap, when clocks are set back, there are two valid offsets. This method uses the earlier offset typically corresponding to "summer".

In the case of a gap, when clocks jump forward, there is no valid offset. Instead, the local date-time is adjusted to be later by the length of the gap. For a typical one hour daylight savings change, the local date-time will be moved one hour later into the offset typically corresponding to "summer".

This method exists primarily for writing test cases. Non test-code will typically use other methods to create an offset time. LocalDateTime has five additional convenience variants of the equivalent factory method taking fewer arguments. They are not provided here to reduce the footprint of the API.
[中]从年、月、日、小时、分钟、秒、纳秒和时区获取ZoneDateTime的实例。
这将创建与七个指定字段的本地日期时间尽可能接近的分区日期时间。时区规则(如夏令时)意味着并非每个本地日期时间都对指定的区域有效,因此可以调整本地日期时间。
本地日期时间解析为时间线上的一个瞬间。这是通过查找由分区ID的分区表定义的本地日期时间与UTC/格林威治的有效偏移量来实现的。
在大多数情况下,本地日期时间只有一个有效偏移量。在重叠的情况下,当时钟被向后设置时,有两个有效偏移。此方法使用通常与“summer”对应的较早偏移量。
在间隙的情况下,当时钟向前跳时,没有有效的偏移。相反,本地日期时间会根据间隔的长度调整为更晚。对于典型的一小时夏令时更改,本地日期时间将在一小时后移动到通常对应于“夏季”的偏移量中。
这种方法主要用于编写测试用例。非测试代码通常会使用其他方法来创建偏移时间。LocalDateTime有五个附加的方便变量,它们是等效工厂方法的变体,使用的参数更少。这里不提供它们是为了减少API的占用空间。

代码示例

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

/**
 * Converts this date-time to a {@code ZonedDateTime} using the offset as the zone ID.
 * <p>
 * This creates the simplest possible {@code ZonedDateTime} using the offset
 * as the zone ID.
 * <p>
 * To control the time-zone used, see {@link #atZoneSameInstant(ZoneId)} and
 * {@link #atZoneSimilarLocal(ZoneId)}.
 *
 * @return a zoned date-time representing the same local date-time and offset, not null
 */
public ZonedDateTime toZonedDateTime() {
  return ZonedDateTime.of(dateTime, offset);
}

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

/**
 * Converts this date-time to a {@code ZonedDateTime} using the offset as the zone ID.
 * <p>
 * This creates the simplest possible {@code ZonedDateTime} using the offset
 * as the zone ID.
 * <p>
 * To control the time-zone used, see {@link #atZoneSameInstant(ZoneId)} and
 * {@link #atZoneSimilarLocal(ZoneId)}.
 *
 * @return a zoned date-time representing the same local date-time and offset, not null
 */
public ZonedDateTime toZonedDateTime() {
  return ZonedDateTime.of(dateTime, offset);
}

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

return ZonedDateTime.of(this, zone);

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

return ZonedDateTime.of(this, zone);

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

/**
 * Obtains an instance of {@code ZonedDateTime} from a local date and time.
 * <p>
 * This creates a zoned date-time matching the input local date and time as closely as possible.
 * Time-zone rules, such as daylight savings, mean that not every local date-time
 * is valid for the specified zone, thus the local date-time may be adjusted.
 * <p>
 * The local date time and first combined to form a local date-time.
 * The local date-time is then resolved to a single instant on the time-line.
 * This is achieved by finding a valid offset from UTC/Greenwich for the local
 * date-time as defined by the {@link ZoneRules rules} of the zone ID.
 *<p>
 * In most cases, there is only one valid offset for a local date-time.
 * In the case of an overlap, when clocks are set back, there are two valid offsets.
 * This method uses the earlier offset typically corresponding to "summer".
 * <p>
 * In the case of a gap, when clocks jump forward, there is no valid offset.
 * Instead, the local date-time is adjusted to be later by the length of the gap.
 * For a typical one hour daylight savings change, the local date-time will be
 * moved one hour later into the offset typically corresponding to "summer".
 *
 * @param date  the local date, not null
 * @param time  the local time, not null
 * @param zone  the time-zone, not null
 * @return the offset date-time, not null
 */
public static ZonedDateTime of(LocalDate date, LocalTime time, ZoneId zone) {
  return of(LocalDateTime.of(date, time), zone);
}

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

/**
 * Obtains an instance of {@code ZonedDateTime} from a local date and time.
 * <p>
 * This creates a zoned date-time matching the input local date and time as closely as possible.
 * Time-zone rules, such as daylight savings, mean that not every local date-time
 * is valid for the specified zone, thus the local date-time may be adjusted.
 * <p>
 * The local date time and first combined to form a local date-time.
 * The local date-time is then resolved to a single instant on the time-line.
 * This is achieved by finding a valid offset from UTC/Greenwich for the local
 * date-time as defined by the {@link ZoneRules rules} of the zone ID.
 *<p>
 * In most cases, there is only one valid offset for a local date-time.
 * In the case of an overlap, when clocks are set back, there are two valid offsets.
 * This method uses the earlier offset typically corresponding to "summer".
 * <p>
 * In the case of a gap, when clocks jump forward, there is no valid offset.
 * Instead, the local date-time is adjusted to be later by the length of the gap.
 * For a typical one hour daylight savings change, the local date-time will be
 * moved one hour later into the offset typically corresponding to "summer".
 *
 * @param date  the local date, not null
 * @param time  the local time, not null
 * @param zone  the time-zone, not null
 * @return the offset date-time, not null
 */
public static ZonedDateTime of(LocalDate date, LocalTime time, ZoneId zone) {
  return of(LocalDateTime.of(date, time), zone);
}

代码示例来源:origin: Ullink/simple-slack-api

@Override
public List<SlackMessagePosted> fetchHistoryOfChannel(String channelId, LocalDate day, int numberOfMessages, Set<String> allowedSubtypes) {
  Map<String, String> params = new HashMap<>();
  params.put("channel", channelId);
  if (day != null) {
    ZonedDateTime start = ZonedDateTime.of(day.atStartOfDay(), ZoneId.of("UTC"));
    ZonedDateTime end = ZonedDateTime.of(day.atStartOfDay().plusDays(1).minus(1, ChronoUnit.MILLIS), ZoneId.of("UTC"));
    params.put("oldest", convertDateToSlackTimestamp(start));
    params.put("latest", convertDateToSlackTimestamp(end));
  }
  if (numberOfMessages > -1) {
    params.put("count", String.valueOf(numberOfMessages));
  } else {
    params.put("count", String.valueOf(DEFAULT_HISTORY_FETCH_SIZE));
  }
  SlackChannel channel = session.findChannelById(channelId);
  switch (channel.getType()) {
    case INSTANT_MESSAGING:
      return fetchHistoryOfChannel(params,FETCH_IM_HISTORY_COMMAND, allowedSubtypes);
    case PRIVATE_GROUP:
      return fetchHistoryOfChannel(params,FETCH_GROUP_HISTORY_COMMAND, allowedSubtypes);
    default:
      return fetchHistoryOfChannel(params,FETCH_CHANNEL_HISTORY_COMMAND, allowedSubtypes);
  }
}

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

return of(ldt, zone);
} catch (DateTimeException ex) {
  throw new DateTimeException("Unable to obtain ZonedDateTime from TemporalAccessor: " +

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

return of(ldt, zone);
} catch (DateTimeException ex) {
  throw new DateTimeException("Unable to obtain ZonedDateTime from TemporalAccessor: " +

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

return ZonedDateTime.of(ldt, zone);

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

return ZonedDateTime.of(ldt, zone);

相关文章