java.time.ZoneId#getId ( )源码实例Demo

下面列出了java.time.ZoneId#getId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Java8CN   文件: DateTimeFormatterBuilder.java
@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 项目: jdk8u60   文件: DateTimeFormatterBuilder.java
@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;
}
 
@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;
}
 
源代码4 项目: jdk8u-jdk   文件: TimeZone.java
/**
 * 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);
}
 
源代码5 项目: hottub   文件: TimeZone.java
/**
 * 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);
}
 
源代码6 项目: dragonwell8_jdk   文件: TimeZone.java
/**
 * 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);
}
 
源代码7 项目: Bytecoder   文件: TimeZone.java
/**
 * 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);
}
 
源代码8 项目: JDKSourceCode1.8   文件: TimeZone.java
/**
 * 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);
}
 
源代码9 项目: cloudbreak   文件: DateServiceTest.java
@Test
public void testIsTriggerWhenTheCurrentTimeEqualsWithTheNextTriggerAndZonesAreEquivalentThenItShouldTriggerAnEvent() {
    ZoneId zone = ZoneId.systemDefault();
    String timeZone = zone.getId();
    ZonedDateTime currentZonedTime = ZonedDateTime.of(2017, 12, 20, 12, 0, 0, 0, zone.normalized());
    long monitorUpdateRate = 60000L;

    when(dateTimeService.getDefaultZonedDateTime()).thenReturn(currentZonedTime);
    when(dateTimeService.getZonedDateTime(currentZonedTime.toInstant(), timeZone)).thenReturn(currentZonedTime);
    TimeAlert timeAlert = createTimeAlert(timeZone);
    assertTrue(underTest.isTrigger(timeAlert, monitorUpdateRate));
}
 
源代码10 项目: desugar_jdk_libs   文件: DesugarTimeZone.java
/**
 * 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 TimeZone.getTimeZone(tzid);  // for desugar: call appropriate public TimeZone method
}
 
@GetMapping("/api/datetime")
public DateTime datetime() {
    ZonedDateTime now = ZonedDateTime.now();
    String date = now.format(DateTimeFormatter.ISO_LOCAL_DATE);
    String time = now.format(DateTimeFormatter.ISO_LOCAL_TIME);
    ZoneId zone = now.getZone();
    ZoneOffset offset = zone.getRules().getOffset(now.toLocalDateTime());
    String zoneString = String.format("%s (%s)",
            zone.getDisplayName(FULL, Locale.UK), zone.getDisplayName(SHORT, Locale.UK));

    return new DateTime(date, time, zoneString, zone.getId(), offset.getId());
}
 
源代码12 项目: threeten-jaxb   文件: ZoneIdXmlAdapter.java
@Override
public String marshal(ZoneId value) {
    return value != null ? value.getId() : null;
}
 
源代码13 项目: alibaba-rsocket-broker   文件: ZoneIdHandle.java
public ZoneIdHandle(ZoneId o) {
    this.zoneId = o.getId();
}
 
public static String toJson(@NonNull final ZoneId zoneId)
{
	return zoneId.getId();
}
 
源代码15 项目: blog_demos   文件: ZoneIdEditor.java
@Override
public String getAsText() {
	ZoneId value = (ZoneId) getValue();
	return (value != null ? value.getId() : "");
}
 
源代码16 项目: morpheus-core   文件: Json.java
@Override
public JsonElement serialize(ZoneId value, Type type, JsonSerializationContext context) {
    return value == null ? JsonNull.INSTANCE : new JsonPrimitive(value.getId());
}
 
源代码17 项目: java-technology-stack   文件: ZoneIdEditor.java
@Override
public String getAsText() {
	ZoneId value = (ZoneId) getValue();
	return (value != null ? value.getId() : "");
}
 
源代码18 项目: hibernate-types   文件: ZoneIdTypeDescriptor.java
public String toString(ZoneId value) {
    return value.getId();
}
 
源代码19 项目: lams   文件: ZoneIdEditor.java
@Override
public String getAsText() {
	ZoneId value = (ZoneId) getValue();
	return (value != null ? value.getId() : "");
}
 
源代码20 项目: datacollector   文件: TimeZoneChooserValues.java
/**
   * Create user visible label for given zone id.
   *
   * The created labels are in format $OFFSET $SHORT ($NAME), e.g.
   *
   * +01:00 CET (Europe/Prague)
   * -07:00 PST (America/Los_Angeles)
   */
//  @VisibleForTesting
  static String getLabelForTimeZoneId(ZoneId zoneId) {
    ZoneOffset zos = LocalDateTime.now().atZone(zoneId).getOffset();

    return zos.getId().replaceAll("Z", "+00:00") + " " + zoneId.getDisplayName(TextStyle.SHORT, Locale.getDefault()) + " (" + zoneId.getId() + ")";
  }