本文整理了Java中java.time.ZoneId.getAvailableZoneIds()
方法的一些代码示例,展示了ZoneId.getAvailableZoneIds()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneId.getAvailableZoneIds()
方法的具体详情如下:
包路径:java.time.ZoneId
类名称:ZoneId
方法名:getAvailableZoneIds
[英]Gets the set of available zone IDs.
This set includes the string form of all available region-based IDs. Offset-based zone IDs are not included in the returned set. The ID can be passed to #of(String) to create a ZoneId.
The set of zone IDs can increase over time, although in a typical application the set of IDs is fixed. Each call to this method is thread-safe.
[中]获取可用区域ID的集合。
该集合包括所有可用的基于区域的ID的字符串形式。返回的集合中不包括基于偏移量的区域ID。可以将ID传递给#of(String)以创建ZoneId。
区域ID集可能会随着时间的推移而增加,尽管在典型应用中,ID集是固定的。对该方法的每次调用都是线程安全的。
代码示例来源:origin: neo4j/neo4j
@Test
void weSupportAllJavaZoneIds()
{
ZoneId.getAvailableZoneIds().forEach( s ->
{
short num = TimeZones.map( s );
assertThat( "Our time zone table does not have a mapping for " + s, num, greaterThanOrEqualTo( (short) 0 ) );
String nameFromTable = TimeZones.map( num );
if ( !s.equals( nameFromTable ) )
{
// The test is running on an older Java version and `s` has been removed since, thus it points to a different zone now.
// That zone should point to itself, however.
assertThat( "Our time zone table has inconsistent mapping for " + nameFromTable,
TimeZones.map( TimeZones.map( nameFromTable ) ), equalTo( nameFromTable ) );
}
} );
}
代码示例来源:origin: prestodb/presto
TreeSet<String> jdkZones = new TreeSet<>(ZoneId.getAvailableZoneIds());
代码示例来源:origin: biezhi/learn-java8
public static void main(String[] args) {
// 获取系统默认时区
ZoneId defaultZoneId = ZoneId.systemDefault();
ZoneId shanghaiZoneId = ZoneId.of("Asia/Shanghai");
// TimeZone 转换为 ZoneId
ZoneId oldToNewZoneId = TimeZone.getDefault().toZoneId();
System.out.println(defaultZoneId);
System.out.println(shanghaiZoneId);
System.out.println(oldToNewZoneId);
System.out.println(ZoneId.getAvailableZoneIds());
}
}
代码示例来源:origin: pholser/junit-quickcheck
@Override public ZoneId generate(SourceOfRandomness random, GenerationStatus status) {
return ZoneId.of(random.choose(getAvailableZoneIds()));
}
}
代码示例来源:origin: apache/metron
private DateTimeFormatter getDateFormatterWithZone(DateTimeFormatter formatter, Map<String, Object> parserConfig) {
String timezone = (String) parserConfig.get("timeZone");
if (StringUtils.isNotEmpty(timezone)) {
if(ZoneId.getAvailableZoneIds().contains(timezone)) {
_LOG.info("Using timezone '{}'", timezone);
return formatter.withZone(ZoneId.of(timezone));
} else {
throw new IllegalArgumentException("Unable to find ZoneId '" + timezone + "'");
}
} else {
_LOG.info("Using default timezone '{}'", ZoneId.systemDefault());
return formatter.withZone(ZoneId.systemDefault());
}
}
代码示例来源:origin: stackoverflow.com
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.TextStyle;
import java.util.Locale;
import java.util.Set;
Set<String> zoneIds = ZoneId.getAvailableZoneIds();
for (String zoneId : zoneIds) {
ZoneId zone = ZoneId.of(zoneId);
ZonedDateTime zonedDateTime = ZonedDateTime.now(zone);
ZoneOffset offset = zonedDateTime.getOffset();
String longName = zone.getDisplayName(TextStyle.FULL, Locale.ENGLISH);
System.out.println("(" + offset + ") " + zoneId + ", " + longName);
}
代码示例来源:origin: kousen/java_8_recipes
public static void main(String[] args) {
System.out.println(ZoneId.getAvailableZoneIds().size());
ZoneId.getAvailableZoneIds()
.forEach(System.out::println);
}
}
代码示例来源:origin: kiegroup/optaweb-employee-rostering
@Override
public List<ZoneId> getSupportedTimezones() {
return ZoneId.getAvailableZoneIds().stream()
.sorted().map(zoneId -> ZoneId.of(zoneId))
.collect(Collectors.toList());
}
}
代码示例来源:origin: eclipse/hawkbit
/**
* Get list of all time zone offsets supported.
*/
private static List<String> getAllTimeZones() {
final List<String> lst = ZoneId.getAvailableZoneIds().stream()
.map(id -> ZonedDateTime.now(ZoneId.of(id)).getOffset().getId().replace("Z", "+00:00")).distinct()
.collect(Collectors.toList());
lst.sort(null);
return lst;
}
代码示例来源:origin: com.pholser/junit-quickcheck-generators
@Override public ZoneId generate(SourceOfRandomness random, GenerationStatus status) {
return ZoneId.of(random.choose(getAvailableZoneIds()));
}
}
代码示例来源:origin: org.eclipse.hawkbit/hawkbit-ui
/**
* Get list of all time zone offsets supported.
*/
private static List<String> getAllTimeZones() {
final List<String> lst = ZoneId.getAvailableZoneIds().stream()
.map(id -> ZonedDateTime.now(ZoneId.of(id)).getOffset().getId().replace("Z", "+00:00")).distinct()
.collect(Collectors.toList());
lst.sort(null);
return lst;
}
代码示例来源:origin: kousen/java_8_recipes
public static List<String> getRegionNamesForOffset(ZoneOffset offset) {
LocalDateTime now = LocalDateTime.now();
return ZoneId.getAvailableZoneIds().stream()
.map(ZoneId::of)
.filter(zoneId -> now.atZone(zoneId).getOffset().equals(offset))
.map(ZoneId::toString)
.sorted()
.collect(Collectors.toList());
}
代码示例来源:origin: mohamed-taman/JavaSE8-Features
public static void main(String[] args) {
DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT);
LocalDateTime currentDT = LocalDateTime.now();
System.out.println(dtf.format(currentDT));
ZonedDateTime gmt = ZonedDateTime.now(ZoneId.of("GMT+0"));
System.out.println(dtf.format(gmt));
ZonedDateTime ny = ZonedDateTime.now(ZoneId.of("America/New_York"));
System.out.println(dtf.format(ny));
Set<String> zones = ZoneId.getAvailableZoneIds();
Predicate<String> condition = str -> str.contains("London");
zones.forEach(z -> {
if(condition.test(z))
System.out.println(z);
});
}
}
代码示例来源:origin: alblue/com.packtpub.e4
public static Map<String, Set<ZoneId>> getTimeZones() {
Supplier<Set<ZoneId>> sortedZones = () -> new TreeSet<>(new TimeZoneComparator());
return ZoneId.getAvailableZoneIds().stream() // stream
.filter(s -> s.contains("/")) // with / in them
.map(ZoneId::of) // convert to ZoneId
.collect(Collectors.groupingBy( // and group by
z -> z.getId().split("/")[0], // first part
TreeMap::new, Collectors.toCollection(sortedZones)));
}
}
代码示例来源:origin: qala-io/datagen
public ZonedDateTime zonedDateTime() {
return ZonedDateTime.ofInstant(instant(), ZoneId.of(sample(ZoneId.getAvailableZoneIds())));
}
public List<ZonedDateTime> zonedDateTimes(int nOfTimes) {
代码示例来源:origin: zavtech/morpheus-core
/**
* Constructor
*/
OfZoneId() {
super(ZoneId.class);
this.zoneIds = ZoneId.getAvailableZoneIds().stream().map(ZoneId::of).toArray(ZoneId[]::new);
this.codeMap = new TObjectIntHashMap<>(zoneIds.length, 0.5f, -1);
Arrays.sort(zoneIds, (z1, z2) -> z1.getId().compareTo(z2.getId()));
for (int i=0; i<zoneIds.length; ++i) {
this.codeMap.put(zoneIds[i], i);
}
}
代码示例来源:origin: kousen/java_8_recipes
public static void main(String[] args) {
LocalDateTime now = LocalDateTime.now();
List<ZonedDateTime> antarticZones =
ZoneId.getAvailableZoneIds().stream() // Stream<String>
.filter(regionId -> regionId.contains("Antarctica"))
.map(ZoneId::of) // Stream<ZoneId>
.map(now::atZone) // Stream<ZonedDateTime>
.sorted(comparingInt(zoneId -> zoneId.getOffset().getTotalSeconds()))
.collect(Collectors.toList());
antarticZones.forEach(zdt ->
System.out.printf("%7s: %25s %7s%n", zdt.getOffset(), zdt.getZone(),
zdt.getZone().getRules().isDaylightSavings(zdt.toInstant())));
}
}
代码示例来源:origin: com.namics.oss/java-random
@Override
public ZonedDateTime random() {
ZonedDateTime now = ZonedDateTime.now().withZoneSameInstant(ZoneId.of(RandomData.random(ZoneId.getAvailableZoneIds())));
int year = 60 * 60 * 24 * 365;
return now.plusSeconds((long) RandomData.randomInteger(-2 * year, 2 * year));// +- 2 years;
}
代码示例来源:origin: arnaudroger/SimpleFlatMapper
private void test501(JdbcMapperBuilder<C501> builder) throws SQLException {
try {
builder.addMapping("zone_id", 1, Types.VARCHAR);
JdbcMapper<C501> mapper = builder.mapper();
String zoneId = ZoneId.getAvailableZoneIds().iterator().next();
ResultSet rs = mock(ResultSet.class);
when(rs.next()).thenReturn(true, false);
when(rs.getString(1)).thenReturn(zoneId);
List<C501> l = mapper.forEach(rs, new ListCollector<C501>()).getList();
assertEquals(1, l.size());
assertEquals(ZoneId.of(zoneId), l.get(0).zoneId);
} catch (Throwable e) {
System.out.println("XXXXXX = " + e);
e.printStackTrace(System.out);
throw e;
}
}
代码示例来源:origin: alblue/com.packtpub.e4
protected void createFieldEditors() {
addField(new IntegerFieldEditor("launchCount", "Number of times it has been launched", getFieldEditorParent()));
IntegerFieldEditor offset = new IntegerFieldEditor("offset", "Current offset from GMT", getFieldEditorParent());
offset.setValidRange(-14, +12);
addField(offset);
String[][] data = ZoneId.getAvailableZoneIds()//
.stream().sorted().map(s -> new String[] { s, s }) //
.collect(Collectors.toList()).toArray(new String[][] {});
addField(new ComboFieldEditor("favorite", "Favorite time zone", data, getFieldEditorParent()));
addField(new BooleanFieldEditor("tick", "Boolean value", getFieldEditorParent()));
addField(new ColorFieldEditor("colour", "Favourite colour", getFieldEditorParent()));
addField(new ScaleFieldEditor("scale", "Scale", getFieldEditorParent(), 0, 360, 10, 90));
addField(new FileFieldEditor("file", "Pick a file", getFieldEditorParent()));
addField(new DirectoryFieldEditor("dir", "Pick a directory", getFieldEditorParent()));
addField(new PathEditor("path", "Path", "Directory", getFieldEditorParent()));
addField(new RadioGroupFieldEditor("group", "Radio choices", 3, data, getFieldEditorParent(), true));
}
内容来源于网络,如有侵权,请联系作者删除!