本文整理了Java中org.threeten.bp.ZoneId.of()
方法的一些代码示例,展示了ZoneId.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneId.of()
方法的具体详情如下:
包路径:org.threeten.bp.ZoneId
类名称: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.
[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.[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);
}
内容来源于网络,如有侵权,请联系作者删除!