本文整理了Java中org.threeten.bp.zone.ZoneRulesProvider.getRules()
方法的一些代码示例,展示了ZoneRulesProvider.getRules()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneRulesProvider.getRules()
方法的具体详情如下:
包路径:org.threeten.bp.zone.ZoneRulesProvider
类名称:ZoneRulesProvider
方法名:getRules
[英]Gets the rules for the zone ID.
This returns the latest available rules for the zone ID.
This method relies on time-zone data provider files that are configured. These are loaded using a ServiceLoader.
The caching flag is designed to allow provider implementations to prevent the rules being cached in ZoneId. Under normal circumstances, the caching of zone rules is highly desirable as it will provide greater performance. However, there is a use case where the caching would not be desirable, see #provideRules.
[中]获取区域ID的规则。
这将返回区域ID的最新可用规则。
此方法依赖于已配置的时区数据提供程序文件。这些都是使用ServiceLoader加载的。
缓存标志旨在允许提供程序实现防止在ZoneId中缓存规则。在正常情况下,缓存区域规则是非常可取的,因为它将提供更高的性能。但是,有一种情况下缓存是不可取的,请参见#provideRules。
代码示例来源:origin: ThreeTen/threetenbp
@Override
public ZoneRules getRules() {
// additional query for group provider when null allows for possibility
// that the provider was added after the ZoneId was created
return (rules != null ? rules : ZoneRulesProvider.getRules(id, false));
}
代码示例来源:origin: org.threeten/threetenbp
@Override
public ZoneRules getRules() {
// additional query for group provider when null allows for possibility
// that the provider was added after the ZoneId was created
return (rules != null ? rules : ZoneRulesProvider.getRules(id, false));
}
代码示例来源:origin: gabrielittner/lazythreetenbp
private SortedMap<String, ZoneRules> generateZones(String... zoneIds) throws IOException {
SortedMap<String, ZoneRules> zones = new TreeMap<>();
for (String zoneId : zoneIds) {
zones.put(zoneId, ZoneRulesProvider.getRules(zoneId, false));
}
zoneWriter.writeZones(zones);
return zones;
}
代码示例来源:origin: ThreeTen/threetenbp
/**
* Obtains an instance of {@code ZoneId} from an identifier.
*
* @param zoneId the time-zone ID, not null
* @param checkAvailable whether to check if the zone ID is available
* @return the zone ID, not null
* @throws DateTimeException if the ID format is invalid
* @throws DateTimeException if checking availability and the ID cannot be found
*/
static ZoneRegion ofId(String zoneId, boolean checkAvailable) {
Jdk8Methods.requireNonNull(zoneId, "zoneId");
if (zoneId.length() < 2 || PATTERN.matcher(zoneId).matches() == false) {
throw new DateTimeException("Invalid ID for region-based ZoneId, invalid format: " + zoneId);
}
ZoneRules rules = null;
try {
// always attempt load for better behavior after deserialization
rules = ZoneRulesProvider.getRules(zoneId, true);
} catch (ZoneRulesException ex) {
// special case as removed from data file
if (zoneId.equals("GMT0")) {
rules = ZoneOffset.UTC.getRules();
} else if (checkAvailable) {
throw ex;
}
}
return new ZoneRegion(zoneId, rules);
}
代码示例来源:origin: org.threeten/threetenbp
/**
* Obtains an instance of {@code ZoneId} from an identifier.
*
* @param zoneId the time-zone ID, not null
* @param checkAvailable whether to check if the zone ID is available
* @return the zone ID, not null
* @throws DateTimeException if the ID format is invalid
* @throws DateTimeException if checking availability and the ID cannot be found
*/
static ZoneRegion ofId(String zoneId, boolean checkAvailable) {
Jdk8Methods.requireNonNull(zoneId, "zoneId");
if (zoneId.length() < 2 || PATTERN.matcher(zoneId).matches() == false) {
throw new DateTimeException("Invalid ID for region-based ZoneId, invalid format: " + zoneId);
}
ZoneRules rules = null;
try {
// always attempt load for better behavior after deserialization
rules = ZoneRulesProvider.getRules(zoneId, true);
} catch (ZoneRulesException ex) {
// special case as removed from data file
if (zoneId.equals("GMT0")) {
rules = ZoneOffset.UTC.getRules();
} else if (checkAvailable) {
throw ex;
}
}
return new ZoneRegion(zoneId, rules);
}
代码示例来源:origin: gabrielittner/lazythreetenbp
/**
* Call on background thread to eagerly load all zones. Starts with loading
* {@link ZoneId#systemDefault()} which is the one most likely to be used.
*/
@WorkerThread
public static void cacheZones() {
ZoneId.systemDefault().getRules();
for (String zoneId : ZoneRulesProvider.getAvailableZoneIds()) {
ZoneRulesProvider.getRules(zoneId, true);
}
}
内容来源于网络,如有侵权,请联系作者删除!