java.util.TimeZone.getAvailableIDs()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(159)

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

TimeZone.getAvailableIDs介绍

[英]Gets all the available IDs supported.
[中]获取支持的所有可用ID。

代码示例

代码示例来源:origin: stackoverflow.com

import java.util.TimeZone;

public class Test {
  public static void main(String[] args) throws Exception {
    long startOf1900Utc = -2208988800000L;
    for (String id : TimeZone.getAvailableIDs()) {
      TimeZone zone = TimeZone.getTimeZone(id);
      if (zone.getRawOffset() != zone.getOffset(startOf1900Utc - 1)) {
        System.out.println(id);
      }
    }
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Checks if given timezone string is supported by TimeZone and returns
 * the same string if valid, null otherwise
 * @since 1.615
 */
public static @CheckForNull String getValidTimezone(String timezone) {
  String[] validIDs = TimeZone.getAvailableIDs();
  for (String str : validIDs) {
     if (str != null && str.equals(timezone)) {
        return timezone;
     }
  }
  return null;
}

代码示例来源:origin: pentaho/pentaho-kettle

public static String[] getTimeZones() {
 String[] timeZones = TimeZone.getAvailableIDs();
 Arrays.sort( timeZones );
 return timeZones;
}

代码示例来源:origin: stackoverflow.com

for (String string : TimeZone.getAvailableIDs(TimeZone.getTimeZone(
    "GMT+02:00").getRawOffset())) {
  System.out.println(string);
}

代码示例来源:origin: zalando/zalenium

public static void setConfiguredTimeZone(String configuredTimeZone) {
  if (!Arrays.asList(TimeZone.getAvailableIDs()).contains(configuredTimeZone)) {
    LOGGER.warn(String.format("%s is not a real time zone.", configuredTimeZone));
    DockeredSeleniumStarter.configuredTimeZone = DEFAULT_TZ;
  } else {
    DockeredSeleniumStarter.configuredTimeZone = TimeZone.getTimeZone(configuredTimeZone);
  }
}

代码示例来源:origin: com.alibaba/fastjson

protected void setTimeZone(char timeZoneFlag, char t0, char t1, char t3, char t4) {
  int timeZoneOffset = ((t0 - '0') * 10 + (t1 - '0')) * 3600 * 1000;
  timeZoneOffset += ((t3 - '0') * 10 + (t4 - '0')) * 60 * 1000;
  if (timeZoneFlag == '-') {
    timeZoneOffset = -timeZoneOffset;
  }
  if (calendar.getTimeZone().getRawOffset() != timeZoneOffset) {
    String[] timeZoneIDs = TimeZone.getAvailableIDs(timeZoneOffset);
    if (timeZoneIDs.length > 0) {
      TimeZone timeZone = TimeZone.getTimeZone(timeZoneIDs[0]);
      calendar.setTimeZone(timeZone);
    }
  }
}

代码示例来源:origin: zalando/zalenium

private TimeZone getConfiguredTimeZoneFromCapabilities(Map<String, Object> requestedCapability) {
  List<String> timeZoneCapabilities = Arrays.asList(ZaleniumCapabilityType.TIME_ZONE_NO_PREFIX,
      ZaleniumCapabilityType.TIME_ZONE);
  TimeZone timeZone = getConfiguredTimeZone();
  for (String timeZoneCapability : timeZoneCapabilities) {
    if (requestedCapability.containsKey(timeZoneCapability)) {
      String timeZoneFromCapabilities = requestedCapability.get(timeZoneCapability).toString();
      if (Arrays.asList(TimeZone.getAvailableIDs()).contains(timeZoneFromCapabilities)) {
        timeZone = TimeZone.getTimeZone(timeZoneFromCapabilities);
      }
    }
  }
  return timeZone;
}

代码示例来源:origin: stackoverflow.com

AVAILABLE_IDS.addAll(Arrays.asList(TimeZone.getAvailableIDs()));

代码示例来源:origin: org.apache.commons/commons-lang3

@Parameterized.Parameters
public static Collection<TimeZone> data() {
  final String[] zoneIds = TimeZone.getAvailableIDs();
  final List<TimeZone> timeZones = new ArrayList<>();
  for (final String zoneId : zoneIds) {
    timeZones.add(TimeZone.getTimeZone(zoneId));
  }
  return timeZones;
}

代码示例来源:origin: prestodb/presto

TreeSet<String> jdkZones = new TreeSet<>(Arrays.asList(TimeZone.getAvailableIDs()));

代码示例来源:origin: jphp-group/jphp

@Signature(@Arg(value = "rawOffset", optional = @Optional("null")))
public static Memory getAvailableIDs(Environment env, Memory... args) {
  if (args[0].isNull())
    return ArrayMemory.ofStrings(TimeZone.getAvailableIDs()).toConstant();
  else
    return ArrayMemory.ofStrings(TimeZone.getAvailableIDs(args[0].toInteger())).toConstant();
}

代码示例来源:origin: wildfly/wildfly

String[] availableTimeZoneIDs = TimeZone.getAvailableIDs();
if (availableTimeZoneIDs != null && Arrays.asList(availableTimeZoneIDs).contains(timezoneId)) {
  this.timezone = TimeZone.getTimeZone(timezoneId);

代码示例来源:origin: benas/random-beans

@Override
  public TimeZone getRandomValue() {
    String[] timeZoneIds = TimeZone.getAvailableIDs();
    return TimeZone.getTimeZone(timeZoneIds[random.nextInt(timeZoneIds.length)]);
  }
}

代码示例来源:origin: com.alibaba/fastjson

String[] timeZoneIDs = TimeZone.getAvailableIDs(0);
  if (timeZoneIDs.length > 0) {
    TimeZone timeZone = TimeZone.getTimeZone(timeZoneIDs[0]);
timzeZoneLength = 1;
if (calendar.getTimeZone().getRawOffset() != 0) {
  String[] timeZoneIDs = TimeZone.getAvailableIDs(0);
  if (timeZoneIDs.length > 0) {
    TimeZone timeZone = TimeZone.getTimeZone(timeZoneIDs[0]);

代码示例来源:origin: pholser/junit-quickcheck

@Override public TimeZone generate(SourceOfRandomness random, GenerationStatus status) {
    return getTimeZone(random.choose(getAvailableIDs()));
  }
}

代码示例来源:origin: naver/ngrinder

/**
 * Get time zones.
 * 
 * @return map time zone id and GMT
 */
public static Map<String, String> getFilteredTimeZoneMap() {
  if (timezoneIDMap == null) {
    timezoneIDMap = new LinkedHashMap<String, String>();
    String[] ids = TimeZone.getAvailableIDs();
    for (String id : ids) {
      TimeZone zone = TimeZone.getTimeZone(id);
      int offset = zone.getRawOffset();
      int offsetSecond = offset / CONSTANT_1000;
      int hour = offsetSecond / (CONSTANT_60 * CONSTANT_60);
      int minutes = (offsetSecond % (CONSTANT_60 * CONSTANT_60)) / CONSTANT_60;
      timezoneIDMap.put(TimeZone.getTimeZone(id).getDisplayName(),
              String.format("(GMT%+d:%02d) %s", hour, minutes, id));
    }
  }
  return timezoneIDMap;
}

代码示例来源:origin: stackoverflow.com

ArrayAdapter <CharSequence> adapter =
    new ArrayAdapter <CharSequence> (this, android.R.layout.simple_spinner_item );
 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
 String[]TZ = TimeZone.getAvailableIDs();
 ArrayList<String> TZ1 = new ArrayList<String>();
 for(int i = 0; i < TZ.length; i++) {
   if(!(TZ1.contains(TimeZone.getTimeZone(TZ[i]).getDisplayName()))) {
     TZ1.add(TimeZone.getTimeZone(TZ[i]).getDisplayName());
   }
 }
 for(int i = 0; i < TZ1.size(); i++) {
   adapter.add(TZ1.get(i));
 }
 final Spinner TZone = (Spinner)findViewById(R.id.TimeZoneEntry);
 TZone.setAdapter(adapter);
 for(int i = 0; i < TZ1.size(); i++) {
   if(TZ1.get(i).equals(TimeZone.getDefault().getDisplayName())) {
     TZone.setSelection(i);
   }
 }

代码示例来源:origin: b3log/latke

private TimeZones() {
  HashSet<String> availableIdsSet = new HashSet<>(Arrays.asList(TimeZone.getAvailableIDs()));
  for (TimeZoneMapping zoneMapping : ZONEMAPPINGS) {
    String id = zoneMapping.getOlsonName();
    if (!availableIdsSet.contains(id)) {
      throw new IllegalStateException("Unknown ID [" + id + "]");
    }
    TimeZone timeZone = TimeZone.getTimeZone(id);
    timeZones.add(new TimeZoneWithDisplayNames(timeZone, zoneMapping.getWindowsDisplayName(),
        zoneMapping.getWindowsStandardName()));
  }
  Collections.sort(timeZones, (a, b) -> {
    int diff = a.getTimeZone().getRawOffset() - b.getTimeZone().getRawOffset();
    if (diff < 0) {
      return -1;
    } else if (diff > 0) {
      return 1;
    } else {
      return a.getDisplayName().compareTo(b.getDisplayName());
    }
  });
}

代码示例来源:origin: apache/cloudstack

@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
  _configs = _configDao.getConfiguration();
  final String value = _configs.get("event.purge.interval");
  final int cleanup = NumbersUtil.parseInt(value, 60 * 60 * 24); // 1 day.
  _purgeDelay = NumbersUtil.parseInt(_configs.get("event.purge.delay"), 0);
  if (_purgeDelay != 0) {
    _eventExecutor.scheduleAtFixedRate(new EventPurgeTask(), cleanup, cleanup, TimeUnit.SECONDS);
  }
  //Alerts purge configurations
  final int alertPurgeInterval = NumbersUtil.parseInt(_configDao.getValue(Config.AlertPurgeInterval.key()), 60 * 60 * 24); // 1 day.
  _alertPurgeDelay = NumbersUtil.parseInt(_configDao.getValue(Config.AlertPurgeDelay.key()), 0);
  if (_alertPurgeDelay != 0) {
    _alertExecutor.scheduleAtFixedRate(new AlertPurgeTask(), alertPurgeInterval, alertPurgeInterval, TimeUnit.SECONDS);
  }
  final String[] availableIds = TimeZone.getAvailableIDs();
  _availableIdsMap = new HashMap<String, Boolean>(availableIds.length);
  for (final String id : availableIds) {
    _availableIdsMap.put(id, true);
  }
  supportedHypervisors.add(HypervisorType.KVM);
  supportedHypervisors.add(HypervisorType.XenServer);
  return true;
}

代码示例来源:origin: HubSpot/Singularity

if (!ArrayUtils.contains(TimeZone.getAvailableIDs(), request.getScheduleTimeZone().get())) {
 badRequest("scheduleTimeZone %s does not map to a valid Java TimeZone object (e.g. 'US/Eastern' or 'GMT')", request.getScheduleTimeZone().get());

相关文章