本文整理汇总了Java中java.time.ZoneId.getId方法的典型用法代码示例。如果您正苦于以下问题:Java ZoneId.getId方法的具体用法?Java ZoneId.getId怎么用?Java ZoneId.getId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.ZoneId
的用法示例。
在下文中一共展示了ZoneId.getId方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: format
import java.time.ZoneId; //导入方法依赖的package包/类
@Override
public boolean format(DateTimePrintContext context, StringBuilder buf) {
ZoneId zone = context.getValue(TemporalQueries.zoneId());
if (zone == null) {
return false;
}
String zname = zone.getId();
if (!(zone instanceof ZoneOffset)) {
TemporalAccessor dt = context.getTemporal();
String name = getDisplayName(zname,
dt.isSupported(ChronoField.INSTANT_SECONDS)
? (zone.getRules().isDaylightSavings(Instant.from(dt)) ? DST : STD)
: GENERIC,
context.getLocale());
if (name != null) {
zname = name;
}
}
buf.append(zname);
return true;
}
示例2: getTimeZone
import java.time.ZoneId; //导入方法依赖的package包/类
/**
* Gets the {@code TimeZone} for the given {@code zoneId}.
*
* @param zoneId a {@link ZoneId} from which the time zone ID is obtained
* @return the specified {@code TimeZone}, or the GMT zone if the given ID
* cannot be understood.
* @throws NullPointerException if {@code zoneId} is {@code null}
* @since 1.8
*/
public static TimeZone getTimeZone(ZoneId zoneId) {
String tzid = zoneId.getId(); // throws an NPE if null
char c = tzid.charAt(0);
if (c == '+' || c == '-') {
tzid = "GMT" + tzid;
} else if (c == 'Z' && tzid.length() == 1) {
tzid = "UTC";
}
return getTimeZone(tzid, true);
}
示例3: format
import java.time.ZoneId; //导入方法依赖的package包/类
@Override
public boolean format(DateTimePrintContext context, StringBuilder buf) {
ZoneId zone = context.getValue(TemporalQueries.zoneId());
if (zone == null) {
return false;
}
String zname = zone.getId();
if (!(zone instanceof ZoneOffset)) {
TemporalAccessor dt = context.getTemporal();
int type = GENERIC;
if (!isGeneric) {
if (dt.isSupported(ChronoField.INSTANT_SECONDS)) {
type = zone.getRules().isDaylightSavings(Instant.from(dt)) ? DST : STD;
} else if (dt.isSupported(ChronoField.EPOCH_DAY) &&
dt.isSupported(ChronoField.NANO_OF_DAY)) {
LocalDate date = LocalDate.ofEpochDay(dt.getLong(ChronoField.EPOCH_DAY));
LocalTime time = LocalTime.ofNanoOfDay(dt.getLong(ChronoField.NANO_OF_DAY));
LocalDateTime ldt = date.atTime(time);
if (zone.getRules().getTransition(ldt) == null) {
type = zone.getRules().isDaylightSavings(ldt.atZone(zone).toInstant()) ? DST : STD;
}
}
}
String name = getDisplayName(zname, type, context.getLocale());
if (name != null) {
zname = name;
}
}
buf.append(zname);
return true;
}
示例4: apply
import java.time.ZoneId; //导入方法依赖的package包/类
@Override
public final String apply(ZoneId input) {
if (input == null) {
final String nullString = getNullValue().get();
return nullString != null ? nullString : "null";
} else {
return input.getId();
}
}
示例5: getAsText
import java.time.ZoneId; //导入方法依赖的package包/类
@Override
public String getAsText() {
ZoneId value = (ZoneId) getValue();
return (value != null ? value.getId() : "");
}
示例6: serialize
import java.time.ZoneId; //导入方法依赖的package包/类
@Override
public JsonElement serialize(ZoneId value, Type type, JsonSerializationContext context) {
return value == null ? JsonNull.INSTANCE : new JsonPrimitive(value.getId());
}