本文整理了Java中org.threeten.bp.ZoneOffset.getId()
方法的一些代码示例,展示了ZoneOffset.getId()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneOffset.getId()
方法的具体详情如下:
包路径:org.threeten.bp.ZoneOffset
类名称:ZoneOffset
方法名:getId
[英]Gets the normalized zone offset ID.
The ID is minor variation to the standard ISO-8601 formatted string for the offset. There are three formats:
代码示例来源:origin: ThreeTen/threetenbp
/**
* Obtains an instance of {@code ZoneOffset} specifying the total offset in seconds
* <p>
* The offset must be in the range {@code -18:00} to {@code +18:00}, which corresponds to -64800 to +64800.
*
* @param totalSeconds the total time-zone offset in seconds, from -64800 to +64800
* @return the ZoneOffset, not null
* @throws DateTimeException if the offset is not in the required range
*/
public static ZoneOffset ofTotalSeconds(int totalSeconds) {
if (Math.abs(totalSeconds) > MAX_SECONDS) {
throw new DateTimeException("Zone offset not in valid range: -18:00 to +18:00");
}
if (totalSeconds % (15 * SECONDS_PER_MINUTE) == 0) {
Integer totalSecs = totalSeconds;
ZoneOffset result = SECONDS_CACHE.get(totalSecs);
if (result == null) {
result = new ZoneOffset(totalSeconds);
SECONDS_CACHE.putIfAbsent(totalSecs, result);
result = SECONDS_CACHE.get(totalSecs);
ID_CACHE.putIfAbsent(result.getId(), result);
}
return result;
} else {
return new ZoneOffset(totalSeconds);
}
}
代码示例来源:origin: org.threeten/threetenbp
/**
* Obtains an instance of {@code ZoneOffset} specifying the total offset in seconds
* <p>
* The offset must be in the range {@code -18:00} to {@code +18:00}, which corresponds to -64800 to +64800.
*
* @param totalSeconds the total time-zone offset in seconds, from -64800 to +64800
* @return the ZoneOffset, not null
* @throws DateTimeException if the offset is not in the required range
*/
public static ZoneOffset ofTotalSeconds(int totalSeconds) {
if (Math.abs(totalSeconds) > MAX_SECONDS) {
throw new DateTimeException("Zone offset not in valid range: -18:00 to +18:00");
}
if (totalSeconds % (15 * SECONDS_PER_MINUTE) == 0) {
Integer totalSecs = totalSeconds;
ZoneOffset result = SECONDS_CACHE.get(totalSecs);
if (result == null) {
result = new ZoneOffset(totalSeconds);
SECONDS_CACHE.putIfAbsent(totalSecs, result);
result = SECONDS_CACHE.get(totalSecs);
ID_CACHE.putIfAbsent(result.getId(), result);
}
return result;
} else {
return new ZoneOffset(totalSeconds);
}
}
代码示例来源:origin: ngs-doo/dsl-json
private static void writeTimezone(final int position, final OffsetDateTime dt, final JsonWriter sw) {
final ZoneOffset zone = dt.getOffset();
sw.advance(position);
sw.writeAscii(zone.getId());
sw.writeByte(JsonWriter.QUOTE);
}
代码示例来源:origin: org.threeten/threetenbp
/**
* Obtains an instance of {@code ZoneId} wrapping an offset.
* <p>
* If the prefix is "GMT", "UTC", or "UT" a {@code ZoneId}
* with the prefix and the non-zero offset is returned.
* If the prefix is empty {@code ""} the {@code ZoneOffset} is returned.
*
* @param prefix the time-zone ID, not null
* @param offset the offset, not null
* @return the zone ID, not null
* @throws IllegalArgumentException if the prefix is not one of
* "GMT", "UTC", or "UT", or ""
*/
public static ZoneId ofOffset(String prefix, ZoneOffset offset) {
Jdk8Methods.requireNonNull(prefix, "prefix");
Jdk8Methods.requireNonNull(offset, "offset");
if (prefix.length() == 0) {
return offset;
}
if (prefix.equals("GMT") || prefix.equals("UTC") || prefix.equals("UT")) {
if (offset.getTotalSeconds() == 0) {
return new ZoneRegion(prefix, offset.getRules());
}
return new ZoneRegion(prefix + offset.getId(), offset.getRules());
}
throw new IllegalArgumentException("Invalid prefix, must be GMT, UTC or UT: " + prefix);
}
代码示例来源:origin: ThreeTen/threetenbp
/**
* Obtains an instance of {@code ZoneId} wrapping an offset.
* <p>
* If the prefix is "GMT", "UTC", or "UT" a {@code ZoneId}
* with the prefix and the non-zero offset is returned.
* If the prefix is empty {@code ""} the {@code ZoneOffset} is returned.
*
* @param prefix the time-zone ID, not null
* @param offset the offset, not null
* @return the zone ID, not null
* @throws IllegalArgumentException if the prefix is not one of
* "GMT", "UTC", or "UT", or ""
*/
public static ZoneId ofOffset(String prefix, ZoneOffset offset) {
Jdk8Methods.requireNonNull(prefix, "prefix");
Jdk8Methods.requireNonNull(offset, "offset");
if (prefix.length() == 0) {
return offset;
}
if (prefix.equals("GMT") || prefix.equals("UTC") || prefix.equals("UT")) {
if (offset.getTotalSeconds() == 0) {
return new ZoneRegion(prefix, offset.getRules());
}
return new ZoneRegion(prefix + offset.getId(), offset.getRules());
}
throw new IllegalArgumentException("Invalid prefix, must be GMT, UTC or UT: " + prefix);
}
代码示例来源:origin: ThreeTen/threetenbp
return new ZoneRegion(zoneId.substring(0, 3), offset.getRules());
return new ZoneRegion(zoneId.substring(0, 3) + offset.getId(), offset.getRules());
return new ZoneRegion("UT", offset.getRules());
return new ZoneRegion("UT" + offset.getId(), offset.getRules());
代码示例来源:origin: org.threeten/threetenbp
return new ZoneRegion(zoneId.substring(0, 3), offset.getRules());
return new ZoneRegion(zoneId.substring(0, 3) + offset.getId(), offset.getRules());
return new ZoneRegion("UT", offset.getRules());
return new ZoneRegion("UT" + offset.getId(), offset.getRules());
代码示例来源:origin: ThreeTen/threetenbp
return new ZoneRegion(zoneId.substring(0, 3), offset.getRules());
return new ZoneRegion(zoneId.substring(0, 3) + offset.getId(), offset.getRules());
return new ZoneRegion("UT", offset.getRules());
return new ZoneRegion("UT" + offset.getId(), offset.getRules());
代码示例来源:origin: org.threeten/threetenbp
return new ZoneRegion(zoneId.substring(0, 3), offset.getRules());
return new ZoneRegion(zoneId.substring(0, 3) + offset.getId(), offset.getRules());
return new ZoneRegion("UT", offset.getRules());
return new ZoneRegion("UT" + offset.getId(), offset.getRules());
内容来源于网络,如有侵权,请联系作者删除!