gpt4 book ai didi

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

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

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

ZoneId.of介绍

[英]Obtains an instance of ZoneId from an ID ensuring that the ID is valid and available for use.

This method parses the ID producing a ZoneId or ZoneOffset. A ZoneOffset is returned if the ID is 'Z', or starts with '+' or '-'. The result will always be a valid ID for which ZoneRules can be obtained.

Parsing matches the zone ID step by step as follows.

  • If the zone ID equals 'Z', the result is ZoneOffset.UTC.
  • If the zone ID consists of a single letter, the zone ID is invalid and DateTimeException is thrown.
  • If the zone ID starts with '+' or '-', the ID is parsed as a ZoneOffset using ZoneOffset#of(String).
  • If the zone ID equals 'GMT', 'UTC' or 'UT' then the result is a ZoneIdwith the same ID and rules equivalent to ZoneOffset.UTC.
  • If the zone ID starts with 'UTC+', 'UTC-', 'GMT+', 'GMT-', 'UT+' or 'UT-' then the ID is a prefixed offset-based ID. The ID is split in two, with a two or three letter prefix and a suffix starting with the sign. The suffix is parsed as a ZoneOffset#of(String). The result will be a ZoneId with the specified UTC/GMT/UT prefix and the normalized offset ID as per ZoneOffset#getId(). The rules of the returned ZoneId will be equivalent to the parsed ZoneOffset.
  • All other IDs are parsed as region-based zone IDs. Region IDs must match the regular expression [A-Za-z][A-Za-z0-9~/._+-]+ otherwise a DateTimeException is thrown. If the zone ID is not in the configured set of IDs, ZoneRulesException is thrown. The detailed format of the region ID depends on the group supplying the data. The default set of data is supplied by the IANA Time Zone Database (TZDB). This has region IDs of the form '{area}/{city}', such as 'Europe/Paris' or 'America/New_York'. This is compatible with most IDs from java.util.TimeZone.
    [中]从ID获取ZoneId的实例,确保该ID有效且可供使用。
    此方法解析产生ZoneId或ZoneOffset的ID。如果ID为“Z”,或以“+”或“-”开头,则返回ZoneOffset。结果将始终是可以获得ZoneRules的有效ID。
    解析按如下步骤逐步匹配区域ID。
    *如果分区ID等于“Z”,则结果为ZoneOffset。UTC。
    *如果区域ID由单个字母组成,则区域ID无效,并引发DateTimeException。
    *如果区域ID以“+”或“-”开头,则使用ZoneOffset#of(String)将ID解析为ZoneOffset。
    *如果区域ID等于“GMT”、“UTC”或“UT”,则结果是一个具有相同ID和与ZoneOffset等效的规则的区域ID。UTC。
    *如果区域ID以“UTC+”、“UTC-”、“GMT+”、“GMT-”、“UT+”或“UT-”开头,则该ID是基于偏移量的前缀ID。该ID被一分为二,前缀为两个或三个字母,后缀以符号开头。后缀被解析为(字符串)的区域偏移。结果将是一个带有指定UTC/GMT/UT前缀和根据ZoneOffset#getId()的标准化偏移ID的区域ID。返回的ZoneId的规则将等同于解析的ZoneOffset。
    *所有其他ID都被解析为基于区域的区域ID。区域ID必须与正则表达式[A-Za-z][A-Za-z0-9~/._+-]+匹配,否则会引发DateTimeException。如果区域ID不在已配置的ID集中,则会引发ZoneRulesException。区域ID的详细格式取决于提供数据的组。默认数据集由IANA时区数据库(TZDB)提供。它具有格式为“{area}/{city}”的区域ID,例如“Europe/Paris”或“America/New_York”。这与大多数来自java的ID兼容。util。时区。

代码示例

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

/**
 * Converts a {@code TimeZone} to a {@code ZoneId}.
 * 
 * @param timeZone  the time-zone, not null
 * @return the zone, not null
 */
public static ZoneId toZoneId(TimeZone timeZone) {
  return ZoneId.of(timeZone.getID(), ZoneId.SHORT_IDS);
}

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

/**
 * Converts a {@code TimeZone} to a {@code ZoneId}.
 * 
 * @param timeZone  the time-zone, not null
 * @return the zone, not null
 */
public static ZoneId toZoneId(TimeZone timeZone) {
  return ZoneId.of(timeZone.getID(), ZoneId.SHORT_IDS);
}

代码示例来源:origin: apache/servicemix-bundles

@Nonnull
  @Override
  public ZoneId convert(String source) {
    return ZoneId.of(source);
  }
}

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

private ZoneId convertToZone(Set<String> regionIds, String parsedZoneId, boolean caseSensitive) {
  if (parsedZoneId == null) {
    return null;
  }
  if (caseSensitive) {
    return (regionIds.contains(parsedZoneId) ? ZoneId.of(parsedZoneId) : null);
  } else {
    for (String regionId : regionIds) {
      if (regionId.equalsIgnoreCase(parsedZoneId)) {
        return ZoneId.of(regionId);
      }
    }
    return null;
  }
}

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

private ZoneId convertToZone(Set<String> regionIds, String parsedZoneId, boolean caseSensitive) {
  if (parsedZoneId == null) {
    return null;
  }
  if (caseSensitive) {
    return (regionIds.contains(parsedZoneId) ? ZoneId.of(parsedZoneId) : null);
  } else {
    for (String regionId : regionIds) {
      if (regionId.equalsIgnoreCase(parsedZoneId)) {
        return ZoneId.of(regionId);
      }
    }
    return null;
  }
}

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

/**
 * Gets the system default time-zone.
 * <p>
 * This queries {@link TimeZone#getDefault()} to find the default time-zone
 * and converts it to a {@code ZoneId}. If the system default time-zone is changed,
 * then the result of this method will also change.
 *
 * @return the zone ID, not null
 * @throws DateTimeException if the converted zone ID has an invalid format
 * @throws ZoneRulesException if the converted zone region ID cannot be found
 */
public static ZoneId systemDefault() {
  return ZoneId.of(TimeZone.getDefault().getID(), SHORT_IDS);
}

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

/**
 * Gets the system default time-zone.
 * <p>
 * This queries {@link TimeZone#getDefault()} to find the default time-zone
 * and converts it to a {@code ZoneId}. If the system default time-zone is changed,
 * then the result of this method will also change.
 *
 * @return the zone ID, not null
 * @throws DateTimeException if the converted zone ID has an invalid format
 * @throws ZoneRulesException if the converted zone region ID cannot be found
 */
public static ZoneId systemDefault() {
  return ZoneId.of(TimeZone.getDefault().getID(), SHORT_IDS);
}

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

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

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

/**
 * Obtains an instance of {@code ZoneId} using its ID using a map
 * of aliases to supplement the standard zone IDs.
 * <p>
 * Many users of time-zones use short abbreviations, such as PST for
 * 'Pacific Standard Time' and PDT for 'Pacific Daylight Time'.
 * These abbreviations are not unique, and so cannot be used as IDs.
 * This method allows a map of string to time-zone to be setup and reused
 * within an application.
 *
 * @param zoneId  the time-zone ID, not null
 * @param aliasMap  a map of alias zone IDs (typically abbreviations) to real zone IDs, not null
 * @return the zone ID, not null
 * @throws DateTimeException if the zone ID has an invalid format
 * @throws ZoneRulesException if the zone ID is a region ID that cannot be found
 */
public static ZoneId of(String zoneId, Map<String, String> aliasMap) {
  Jdk8Methods.requireNonNull(zoneId, "zoneId");
  Jdk8Methods.requireNonNull(aliasMap, "aliasMap");
  String id = aliasMap.get(zoneId);
  id = (id != null ? id : zoneId);
  return of(id);
}

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

@Override
public int parse(DateTimeParseContext context, CharSequence text, int position) {
  // this is a poor implementation that handles some but not all of the spec
  // JDK8 has a lot of extra information here
  Map<String, String> ids = new TreeMap<String, String>(LENGTH_COMPARATOR);
  for (String id : ZoneId.getAvailableZoneIds()) {
    ids.put(id, id);
    TimeZone tz = TimeZone.getTimeZone(id);
    int tzstyle = (textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT);
    String textWinter = tz.getDisplayName(false, tzstyle, context.getLocale());
    if (id.startsWith("Etc/") || (!textWinter.startsWith("GMT+") && !textWinter.startsWith("GMT+"))) {
      ids.put(textWinter, id);
    }
    String textSummer = tz.getDisplayName(true, tzstyle, context.getLocale());
    if (id.startsWith("Etc/") || (!textSummer.startsWith("GMT+") && !textSummer.startsWith("GMT+"))) {
      ids.put(textSummer, id);
    }
  }
  for (Entry<String, String> entry : ids.entrySet()) {
    String name = entry.getKey();
    if (context.subSequenceEquals(text, position, name, 0, name.length())) {
      context.setParsed(ZoneId.of(entry.getValue()));
      return position + name.length();
    }
  }
  return ~position;
}

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

@Override
public int parse(DateTimeParseContext context, CharSequence text, int position) {
  // this is a poor implementation that handles some but not all of the spec
  // JDK8 has a lot of extra information here
  Map<String, String> ids = new TreeMap<String, String>(LENGTH_COMPARATOR);
  for (String id : ZoneId.getAvailableZoneIds()) {
    ids.put(id, id);
    TimeZone tz = TimeZone.getTimeZone(id);
    int tzstyle = (textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT);
    String textWinter = tz.getDisplayName(false, tzstyle, context.getLocale());
    if (id.startsWith("Etc/") || (!textWinter.startsWith("GMT+") && !textWinter.startsWith("GMT+"))) {
      ids.put(textWinter, id);
    }
    String textSummer = tz.getDisplayName(true, tzstyle, context.getLocale());
    if (id.startsWith("Etc/") || (!textSummer.startsWith("GMT+") && !textSummer.startsWith("GMT+"))) {
      ids.put(textSummer, id);
    }
  }
  for (Entry<String, String> entry : ids.entrySet()) {
    String name = entry.getKey();
    if (context.subSequenceEquals(text, position, name, 0, name.length())) {
      context.setParsed(ZoneId.of(entry.getValue()));
      return position + name.length();
    }
  }
  return ~position;
}

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

/**
 * Obtains an instance of {@code ZoneId} using its ID using a map
 * of aliases to supplement the standard zone IDs.
 * <p>
 * Many users of time-zones use short abbreviations, such as PST for
 * 'Pacific Standard Time' and PDT for 'Pacific Daylight Time'.
 * These abbreviations are not unique, and so cannot be used as IDs.
 * This method allows a map of string to time-zone to be setup and reused
 * within an application.
 *
 * @param zoneId  the time-zone ID, not null
 * @param aliasMap  a map of alias zone IDs (typically abbreviations) to real zone IDs, not null
 * @return the zone ID, not null
 * @throws DateTimeException if the zone ID has an invalid format
 * @throws ZoneRulesException if the zone ID is a region ID that cannot be found
 */
public static ZoneId of(String zoneId, Map<String, String> aliasMap) {
  Jdk8Methods.requireNonNull(zoneId, "zoneId");
  Jdk8Methods.requireNonNull(aliasMap, "aliasMap");
  String id = aliasMap.get(zoneId);
  id = (id != null ? id : zoneId);
  return of(id);
}

代码示例来源: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: net.oneandone.ical4j/ical4j

private static VTimeZone generateTimezoneForId(String timezoneId) throws ParseException {
  if(!TIMEZONE_DEFINITIONS.contains(timezoneId)){
    return null;
  }
  java.util.TimeZone javaTz = java.util.TimeZone.getTimeZone(timezoneId);
  
  ZoneId zoneId = ZoneId.of(javaTz.getID(), ZoneId.SHORT_IDS);
  
  int rawTimeZoneOffsetInSeconds = javaTz.getRawOffset() / 1000;
  
  VTimeZone timezone = new VTimeZone();
  
  timezone.getProperties().add(new TzId(timezoneId));
  
  addTransitions(zoneId, timezone, rawTimeZoneOffsetInSeconds);
  
  addTransitionRules(zoneId, rawTimeZoneOffsetInSeconds, timezone);
  
  if(timezone.getObservances() == null || timezone.getObservances().isEmpty()){
    timezone.getObservances().add(NO_TRANSITIONS);
  }
  
  return timezone;
}

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

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