gpt4 book ai didi

org.threeten.bp.ZoneOffset类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 19:33:31 27 4
gpt4 key购买 nike

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

ZoneOffset介绍

[英]A time-zone offset from Greenwich/UTC, such as +02:00.

A time-zone offset is the period of time that a time-zone differs from Greenwich/UTC. This is usually a fixed number of hours and minutes.

Different parts of the world have different time-zone offsets. The rules for how offsets vary by place and time of year are captured in the ZoneId class.

For example, Paris is one hour ahead of Greenwich/UTC in winter and two hours ahead in summer. The ZoneId instance for Paris will reference two ZoneOffset instances - a +01:00 instance for winter, and a +02:00 instance for summer.

In 2008, time-zone offsets around the world extended from -12:00 to +14:00. To prevent any problems with that range being extended, yet still provide validation, the range of offsets is restricted to -18:00 to 18:00 inclusive.

This class is designed for use with the ISO calendar system. The fields of hours, minutes and seconds make assumptions that are valid for the standard ISO definitions of those fields. This class may be used with other calendar systems providing the definition of the time fields matches those of the ISO calendar system.

Instances of ZoneOffset must be compared using #equals. Implementations may choose to cache certain common offsets, however applications must not rely on such caching.

Specification for implementors

This class is immutable and thread-safe.
[中]与格林威治/UTC的时区偏移,例如+02:00。
时区偏移是时区与格林威治/UTC不同的时间段。这通常是一个固定的小时和分钟数。
世界上不同的地方有不同的时区偏移。ZoneId类中记录了补偿如何随时间和地点变化的规则。
例如,巴黎在冬季比格林威治/UTC早一个小时,在夏季比格林威治/UTC早两个小时。巴黎的ZoneId实例将引用两个ZoneOffset实例——冬季的+01:00实例和夏季的+02:00实例。
2008年,世界各地的时区偏移从-12:00扩展到+14:00。为了防止扩展该范围时出现任何问题,但仍提供验证,偏移范围限制为-18:00到18:00(含18:00)。
本课程设计用于ISO日历系统。小时、分钟和秒字段做出的假设适用于这些字段的标准ISO定义。如果时间字段的定义与ISO日历系统的定义相匹配,则此类可与其他日历系统一起使用。
区域偏移的实例必须使用#equals进行比较。实现可能会选择缓存某些公共偏移量,但是应用程序不能依赖这种缓存。
####实施者规范
这个类是不可变的,是线程安全的。

代码示例

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

/**
 * Obtains an instance of {@code ZoneOffset} specifying the total offset in seconds
 * <p>
 * The offset must be in the range {@code -18:00} to {@code +18:00}, which corresponds to -64800 to +64800.
 *
 * @param totalSeconds  the total time-zone offset in seconds, from -64800 to +64800
 * @return the ZoneOffset, not null
 * @throws DateTimeException if the offset is not in the required range
 */
public static ZoneOffset ofTotalSeconds(int totalSeconds) {
  if (Math.abs(totalSeconds) > MAX_SECONDS) {
    throw new DateTimeException("Zone offset not in valid range: -18:00 to +18:00");
  }
  if (totalSeconds % (15 * SECONDS_PER_MINUTE) == 0) {
    Integer totalSecs = totalSeconds;
    ZoneOffset result = SECONDS_CACHE.get(totalSecs);
    if (result == null) {
      result = new ZoneOffset(totalSeconds);
      SECONDS_CACHE.putIfAbsent(totalSecs, result);
      result = SECONDS_CACHE.get(totalSecs);
      ID_CACHE.putIfAbsent(result.getId(), result);
    }
    return result;
  } else {
    return new ZoneOffset(totalSeconds);
  }
}

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

/**
 * Writes the state to the stream.
 *
 * @param offset  the offset, not null
 * @param out  the output stream, not null
 * @throws IOException if an error occurs
 */
static void writeOffset(ZoneOffset offset, DataOutput out) throws IOException {
  final int offsetSecs = offset.getTotalSeconds();
  int offsetByte = offsetSecs % 900 == 0 ? offsetSecs / 900 : 127;  // compress to -72 to +72
  out.writeByte(offsetByte);
  if (offsetByte == 127) {
    out.writeInt(offsetSecs);
  }
}

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

@Override
public int hashCode() {
  return 1 ^
      (31 + offset.hashCode()) ^
      1 ^
      (31 + offset.hashCode()) ^
      1;
}

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

/**
 * Creates the wall offset for the local date-time at the end of the window.
 *
 * @param savingsSecs  the amount of savings in use in seconds
 * @return the created date-time epoch second in the wall offset, not null
 */
ZoneOffset createWallOffset(int savingsSecs) {
  return ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingsSecs);
}

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

return new ZoneRegion(zoneId, ZoneOffset.UTC.getRules());
ZoneOffset offset = ZoneOffset.of(zoneId.substring(3));
if (offset.getTotalSeconds() == 0) {
  return new ZoneRegion(zoneId.substring(0, 3), offset.getRules());
return new ZoneRegion(zoneId.substring(0, 3) + offset.getId(), offset.getRules());
ZoneOffset offset = ZoneOffset.of(zoneId.substring(2));
if (offset.getTotalSeconds() == 0) {
  return new ZoneRegion("UT", offset.getRules());
return new ZoneRegion("UT" + offset.getId(), offset.getRules());

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

/**
 * Obtains an instance of {@code ZoneId} wrapping an offset.
 * <p>
 * If the prefix is "GMT", "UTC", or "UT" a {@code ZoneId}
 * with the prefix and the non-zero offset is returned.
 * If the prefix is empty {@code ""} the {@code ZoneOffset} is returned.
 *
 * @param prefix  the time-zone ID, not null
 * @param offset  the offset, not null
 * @return the zone ID, not null
 * @throws IllegalArgumentException if the prefix is not one of
 *     "GMT", "UTC", or "UT", or ""
 */
public static ZoneId ofOffset(String prefix, ZoneOffset offset) {
  Jdk8Methods.requireNonNull(prefix, "prefix");
  Jdk8Methods.requireNonNull(offset, "offset");
  if (prefix.length() == 0) {
    return offset;
  }
  if (prefix.equals("GMT") || prefix.equals("UTC") || prefix.equals("UT")) {
    if (offset.getTotalSeconds() == 0) {
      return new ZoneRegion(prefix, offset.getRules());
    }
    return new ZoneRegion(prefix + offset.getId(), offset.getRules());
  }
  throw new IllegalArgumentException("Invalid prefix, must be GMT, UTC or UT: " + prefix);
}

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

/**
 * Outputs this date-time as a {@code String}, such as {@code 2007-12-03T10:15:30+01:00}.
 * <p>
 * The output will be one of the following ISO-8601 formats:
 * <p><ul>
 * <li>{@code yyyy-MM-dd'T'HH:mmXXXXX}</li>
 * <li>{@code yyyy-MM-dd'T'HH:mm:ssXXXXX}</li>
 * <li>{@code yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX}</li>
 * <li>{@code yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXXXX}</li>
 * <li>{@code yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSSXXXXX}</li>
 * </ul><p>
 * The format used will be the shortest that outputs the full value of
 * the time where the omitted parts are implied to be zero.
 *
 * @return a string representation of this date-time, not null
 */
@Override
public String toString() {
  return dateTime.toString() + offset.toString();
}

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

@Override
public boolean isValidOffset(LocalDateTime dateTime, ZoneOffset offset) {
  return this.offset.equals(offset);
}

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

@Override
  protected ZoneOffset deserialize(String key, DeserializationContext ctxt) throws IOException {
    try {
      return ZoneOffset.of(key);
    } catch (DateTimeException e) {
      return _rethrowDateTimeException(ctxt, ZoneOffset.class, e, key);
    }
  }
}

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

private static void writeTimezone(final int position, final OffsetDateTime dt, final JsonWriter sw) {
  final ZoneOffset zone = dt.getOffset();
  sw.advance(position);
  sw.writeAscii(zone.getId());
  sw.writeByte(JsonWriter.QUOTE);
}

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

@Override
  public ZoneOffset queryFrom(TemporalAccessor temporal) {
    return ZoneOffset.from(temporal);
  }
};

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

/**
 * Constructor.
 *
 * @param totalSeconds  the total time-zone offset in seconds, from -64800 to +64800
 */
private ZoneOffset(int totalSeconds) {
  super();
  this.totalSeconds = totalSeconds;
  id = buildId(totalSeconds);
}

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

StringBuilder buf = new StringBuilder();
buf.append("TransitionRule[")
  .append(offsetBefore.compareTo(offsetAfter) > 0 ? "Gap " : "Overlap ")
  .append(offsetBefore).append(" to ").append(offsetAfter).append(", ");
if (dow != null) {

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

return new ZoneRegion(zoneId, ZoneOffset.UTC.getRules());
ZoneOffset offset = ZoneOffset.of(zoneId.substring(3));
if (offset.getTotalSeconds() == 0) {
  return new ZoneRegion(zoneId.substring(0, 3), offset.getRules());
return new ZoneRegion(zoneId.substring(0, 3) + offset.getId(), offset.getRules());
ZoneOffset offset = ZoneOffset.of(zoneId.substring(2));
if (offset.getTotalSeconds() == 0) {
  return new ZoneRegion("UT", offset.getRules());
return new ZoneRegion("UT" + offset.getId(), offset.getRules());

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

/**
 * Obtains an instance of {@code ZoneId} wrapping an offset.
 * <p>
 * If the prefix is "GMT", "UTC", or "UT" a {@code ZoneId}
 * with the prefix and the non-zero offset is returned.
 * If the prefix is empty {@code ""} the {@code ZoneOffset} is returned.
 *
 * @param prefix  the time-zone ID, not null
 * @param offset  the offset, not null
 * @return the zone ID, not null
 * @throws IllegalArgumentException if the prefix is not one of
 *     "GMT", "UTC", or "UT", or ""
 */
public static ZoneId ofOffset(String prefix, ZoneOffset offset) {
  Jdk8Methods.requireNonNull(prefix, "prefix");
  Jdk8Methods.requireNonNull(offset, "offset");
  if (prefix.length() == 0) {
    return offset;
  }
  if (prefix.equals("GMT") || prefix.equals("UTC") || prefix.equals("UT")) {
    if (offset.getTotalSeconds() == 0) {
      return new ZoneRegion(prefix, offset.getRules());
    }
    return new ZoneRegion(prefix + offset.getId(), offset.getRules());
  }
  throw new IllegalArgumentException("Invalid prefix, must be GMT, UTC or UT: " + prefix);
}

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

/**
 * Outputs this time as a {@code String}, such as {@code 10:15:30+01:00}.
 * <p>
 * The output will be one of the following ISO-8601 formats:
 * <p><ul>
 * <li>{@code HH:mmXXXXX}</li>
 * <li>{@code HH:mm:ssXXXXX}</li>
 * <li>{@code HH:mm:ss.SSSXXXXX}</li>
 * <li>{@code HH:mm:ss.SSSSSSXXXXX}</li>
 * <li>{@code HH:mm:ss.SSSSSSSSSXXXXX}</li>
 * </ul><p>
 * The format used will be the shortest that outputs the full value of
 * the time where the omitted parts are implied to be zero.
 *
 * @return a string representation of this time, not null
 */
@Override
public String toString() {
  return time.toString() + offset.toString();
}

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

/**
 * Creates the wall offset for the local date-time at the end of the window.
 *
 * @param savingsSecs  the amount of savings in use in seconds
 * @return the created date-time epoch second in the wall offset, not null
 */
ZoneOffset createWallOffset(int savingsSecs) {
  return ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingsSecs);
}

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

@Override
public boolean isValidOffset(LocalDateTime dateTime, ZoneOffset offset) {
  return this.offset.equals(offset);
}

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

@Override
public Object deserialize(JsonParser parser, DeserializationContext context) throws IOException
{
  if (parser.hasToken(JsonToken.VALUE_STRING)) {
    String string = parser.getText().trim();
    if (string.length() == 0) {
      return null;
    }
    try {
      switch (_valueType) {
      case TYPE_PERIOD:
        return Period.parse(string);
      case TYPE_ZONE_ID:
        return ZoneId.of(string);
      case TYPE_ZONE_OFFSET:
        return ZoneOffset.of(string);
      }
    } catch (DateTimeException e) {
      _rethrowDateTimeException(parser, context, e, string);
    }
  }
  if (parser.hasToken(JsonToken.VALUE_EMBEDDED_OBJECT)) {
    // 20-Apr-2016, tatu: Related to [databind#1208], can try supporting embedded
    //    values quite easily
    return parser.getEmbeddedObject();
  }
  throw context.wrongTokenException(parser, JsonToken.VALUE_STRING, null);
}

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

@Override
  public ZoneOffset queryFrom(TemporalAccessor temporal) {
    return ZoneOffset.from(temporal);
  }
};

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