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

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

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

ZonedDateTime.ofInstant介绍

[英]Obtains an instance of ZonedDateTime from an Instant.

This creates a zoned date-time with the same instant as that specified. Calling #toInstant() will return an instant equal to the one used here.

Converting an instant to a zoned date-time is simple as there is only one valid offset for each instant.
[中]从瞬间获取ZoneDateTime的实例。
这将创建一个与指定的时刻相同的分区日期时间。调用#toInstant()将返回与此处使用的相同的瞬间。
将一个瞬间转换为分区日期时间很简单,因为每个瞬间只有一个有效偏移量。

代码示例

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

/**
 * Resolves the new local date-time using the offset to identify the instant.
 *
 * @param newDateTime  the new local date-time, not null
 * @return the zoned date-time, not null
 */
private ZonedDateTime resolveInstant(LocalDateTime newDateTime) {
  return ofInstant(newDateTime, offset, zone);
}

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

/**
 * Resolves the new local date-time using the offset to identify the instant.
 *
 * @param newDateTime  the new local date-time, not null
 * @return the zoned date-time, not null
 */
private ZonedDateTime resolveInstant(LocalDateTime newDateTime) {
  return ofInstant(newDateTime, offset, zone);
}

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

/**
 * Obtains an ISO zoned date-time from an instant.
 * <p>
 * This is equivalent to {@link ZonedDateTime#ofInstant(Instant, ZoneId)}.
 *
 * @param instant  the instant to convert, not null
 * @param zone  the zone to use, not null
 * @return the ISO zoned date-time, not null
 * @throws DateTimeException if unable to create the date-time
 */
@Override  // override with covariant return type
public ZonedDateTime zonedDateTime(Instant instant, ZoneId zone) {
  return ZonedDateTime.ofInstant(instant, zone);
}

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

/**
 * Obtains an ISO zoned date-time from an instant.
 * <p>
 * This is equivalent to {@link ZonedDateTime#ofInstant(Instant, ZoneId)}.
 *
 * @param instant  the instant to convert, not null
 * @param zone  the zone to use, not null
 * @return the ISO zoned date-time, not null
 * @throws DateTimeException if unable to create the date-time
 */
@Override  // override with covariant return type
public ZonedDateTime zonedDateTime(Instant instant, ZoneId zone) {
  return ZonedDateTime.ofInstant(instant, zone);
}

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

/**
 * Combines this instant with a time-zone to create a {@code ZonedDateTime}.
 * <p>
 * This returns an {@code ZonedDateTime} formed from this instant at the
 * specified time-zone. An exception will be thrown if the instant is too
 * large to fit into a zoned date-time.
 * <p>
 * This method is equivalent to
 * {@link ZonedDateTime#ofInstant(Instant, ZoneId) ZonedDateTime.ofInstant(this, zone)}.
 *
 * @param zone  the zone to combine with, not null
 * @return the zoned date-time formed from this instant and the specified zone, not null
 * @throws DateTimeException if the result exceeds the supported range
 */
public ZonedDateTime atZone(ZoneId zone) {
  return ZonedDateTime.ofInstant(this, zone);
}

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

/**
 * Combines this date-time with a time-zone to create a {@code ZonedDateTime}
 * ensuring that the result has the same instant.
 * <p>
 * This returns a {@code ZonedDateTime} formed from this date-time and the specified time-zone.
 * This conversion will ignore the visible local date-time and use the underlying instant instead.
 * This avoids any problems with local time-line gaps or overlaps.
 * The result might have different values for fields such as hour, minute an even day.
 * <p>
 * To attempt to retain the values of the fields, use {@link #atZoneSimilarLocal(ZoneId)}.
 * To use the offset as the zone ID, use {@link #toZonedDateTime()}.
 *
 * @param zone  the time-zone to use, not null
 * @return the zoned date-time formed from this date-time, not null
 */
public ZonedDateTime atZoneSameInstant(ZoneId zone) {
  return ZonedDateTime.ofInstant(dateTime, offset, zone);
}

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

/**
 * Combines this instant with a time-zone to create a {@code ZonedDateTime}.
 * <p>
 * This returns an {@code ZonedDateTime} formed from this instant at the
 * specified time-zone. An exception will be thrown if the instant is too
 * large to fit into a zoned date-time.
 * <p>
 * This method is equivalent to
 * {@link ZonedDateTime#ofInstant(Instant, ZoneId) ZonedDateTime.ofInstant(this, zone)}.
 *
 * @param zone  the zone to combine with, not null
 * @return the zoned date-time formed from this instant and the specified zone, not null
 * @throws DateTimeException if the result exceeds the supported range
 */
public ZonedDateTime atZone(ZoneId zone) {
  return ZonedDateTime.ofInstant(this, zone);
}

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

/**
 * Combines this date-time with a time-zone to create a {@code ZonedDateTime}
 * ensuring that the result has the same instant.
 * <p>
 * This returns a {@code ZonedDateTime} formed from this date-time and the specified time-zone.
 * This conversion will ignore the visible local date-time and use the underlying instant instead.
 * This avoids any problems with local time-line gaps or overlaps.
 * The result might have different values for fields such as hour, minute an even day.
 * <p>
 * To attempt to retain the values of the fields, use {@link #atZoneSimilarLocal(ZoneId)}.
 * To use the offset as the zone ID, use {@link #toZonedDateTime()}.
 *
 * @param zone  the time-zone to use, not null
 * @return the zoned date-time formed from this date-time, not null
 */
public ZonedDateTime atZoneSameInstant(ZoneId zone) {
  return ZonedDateTime.ofInstant(dateTime, offset, zone);
}

代码示例来源:origin: mercadolibre/java-sdk

@Override
 public ZonedDateTime apply(FromIntegerArguments a) {
  return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId);
 }
},

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

@Override
  public ZonedDateTime apply(FromIntegerArguments a) {
    return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId);
  }
},

代码示例来源:origin: mercadolibre/java-sdk

@Override
 public ZonedDateTime apply(FromDecimalArguments a) {
  return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId);
 }
},

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

@Override
  public ZonedDateTime apply(FromDecimalArguments a) {
    return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId);
  }
},

代码示例来源:origin: gengstrand/clojure-news-feed

@Override
 public ZonedDateTime apply(FromIntegerArguments a) {
  return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId);
 }
},

代码示例来源:origin: XeroAPI/Xero-Java

@Override
 public ZonedDateTime apply(FromIntegerArguments a) {
  return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId);
 }
},

代码示例来源:origin: gengstrand/clojure-news-feed

@Override
 public ZonedDateTime apply(FromDecimalArguments a) {
  return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId);
 }
},

代码示例来源:origin: XeroAPI/Xero-Java

@Override
 public ZonedDateTime apply(FromDecimalArguments a) {
  return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId);
 }
},

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

/**
 * Converts a {@code Calendar} to a {@code ZonedDateTime}.
 * <p>
 * Note that {@code GregorianCalendar} supports a Julian-Gregorian cutover
 * date and {@code ZonedDateTime} does not so some differences will occur.
 *
 * @param calendar  the calendar, not null
 * @return the instant, not null
 */
public static ZonedDateTime toZonedDateTime(Calendar calendar) {
  Instant instant = Instant.ofEpochMilli(calendar.getTimeInMillis());
  ZoneId zone = toZoneId(calendar.getTimeZone());
  return ZonedDateTime.ofInstant(instant, zone);
}

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

/**
 * Converts a {@code Calendar} to a {@code ZonedDateTime}.
 * <p>
 * Note that {@code GregorianCalendar} supports a Julian-Gregorian cutover
 * date and {@code ZonedDateTime} does not so some differences will occur.
 *
 * @param calendar  the calendar, not null
 * @return the instant, not null
 */
public static ZonedDateTime toZonedDateTime(Calendar calendar) {
  Instant instant = Instant.ofEpochMilli(calendar.getTimeInMillis());
  ZoneId zone = toZoneId(calendar.getTimeZone());
  return ZonedDateTime.ofInstant(instant, zone);
}

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

/**
 * Obtains the current date-time from the specified clock.
 * <p>
 * This will query the specified clock to obtain the current date-time.
 * The zone and offset will be set based on the time-zone in the clock.
 * <p>
 * Using this method allows the use of an alternate clock for testing.
 * The alternate clock may be introduced using {@link Clock dependency injection}.
 *
 * @param clock  the clock to use, not null
 * @return the current date-time, not null
 */
public static ZonedDateTime now(Clock clock) {
  Jdk8Methods.requireNonNull(clock, "clock");
  final Instant now = clock.instant();  // called once
  return ofInstant(now, clock.getZone());
}

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

/**
 * Obtains the current date-time from the specified clock.
 * <p>
 * This will query the specified clock to obtain the current date-time.
 * The zone and offset will be set based on the time-zone in the clock.
 * <p>
 * Using this method allows the use of an alternate clock for testing.
 * The alternate clock may be introduced using {@link Clock dependency injection}.
 *
 * @param clock  the clock to use, not null
 * @return the current date-time, not null
 */
public static ZonedDateTime now(Clock clock) {
  Jdk8Methods.requireNonNull(clock, "clock");
  final Instant now = clock.instant();  // called once
  return ofInstant(now, clock.getZone());
}

相关文章