本文整理了Java中net.time4j.ZonalDateTime
类的一些代码示例,展示了ZonalDateTime
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonalDateTime
类的具体详情如下:
包路径:net.time4j.ZonalDateTime
类名称:ZonalDateTime
[英]Combination of UTC-moment and timezone.
An instance can be created by Moment.inLocalView() or Moment.inZonalView(...). This type mainly serves for various type conversions and incorporates a valid local timestamp as well as an universal time in UTC. If users wish to apply any kind of data manipulation then an object of this type has first to be converted to a local timestamp or to a global UTC-moment. Example:
Moment moment = ...;
ZonalDateTime zdt = moment.inLocalView();
// manipulation on local timeline
PlainTimestamp localTSP = zdt.toTimestamp().plus(30, ClockUnit.SECONDS);
// manipulation on global timeline
Moment globalTSP = zdt.toMoment().plus(30, SI.SECONDS);
This class supports all elements which are supported by Momentand PlainTimestamp, too.
[中]UTC时刻和时区的组合。
实例可以通过瞬间创建。inLocalView()或瞬间。inZonalView(…)。该类型主要用于各种类型转换,并包含一个有效的本地时间戳和一个UTC世界时。如果用户希望应用任何类型的数据操作,那么这种类型的对象必须首先转换为本地时间戳或全局UTC时刻。例子:
Moment moment = ...;
ZonalDateTime zdt = moment.inLocalView();
// manipulation on local timeline
PlainTimestamp localTSP = zdt.toTimestamp().plus(30, ClockUnit.SECONDS);
// manipulation on global timeline
Moment globalTSP = zdt.toMoment().plus(30, SI.SECONDS);
这个类也支持Momentand PlainTimestamp支持的所有元素。
代码示例来源:origin: net.time4j/time4j-core
@Override
public ZonedDateTime from(ZonalDateTime zdt) {
Instant instant = TemporalType.INSTANT.from(zdt.toMoment());
ZoneId zone;
try {
zone = ZoneId.of(zdt.getTimezone().canonical());
} catch (DateTimeException ex) {
ZonalOffset zo = Timezone.of(zdt.getTimezone()).getOffset(zdt.toMoment());
zone = ZoneOffset.of(zo.toString());
}
return ZonedDateTime.ofInstant(instant, zone);
}
代码示例来源:origin: net.time4j/time4j-core
/**
* <p>Erzeugt einen zonalen Moment. </p>
*
* @param tsp zonal timestamp
* @param offset timezone offset
* @return ZonalDateTime
*/
static ZonalDateTime of(
PlainTimestamp tsp,
ZonalOffset offset
) {
return new ZonalDateTime(tsp, offset);
}
代码示例来源:origin: net.time4j/time4j-core
/**
* <p>Converts this instance to a combination of UTC-moment, given timezone and its zonal timestamp. </p>
*
* <p><strong>Attention:</strong> Due to winter/summer-time-changes the resulting zonal timestamp
* ({@link ZonalDateTime#toTimestamp()}) can deviate from this plain timestamp. </p>
*
* @param tz timezone
* @return ZonalDateTime
* @since 3.16/4.13
*/
/*[deutsch]
* <p>Converts this instance to a combination of UTC-moment, given timezone and its zonal timestamp. </p>
*
* <p><strong>Achtung:</strong> Wegen Winter-/Sommerzeitumstellungen kann der resultierende zonale
* Zeitstempel ({@link ZonalDateTime#toTimestamp()}) von diesem Zeitstempel abweichen. </p>
*
* @param tz timezone
* @return ZonalDateTime
* @since 3.16/4.13
*/
public ZonalDateTime inZonalView(Timezone tz) {
Moment m = this.in(tz);
return ZonalDateTime.of(m, tz);
}
代码示例来源:origin: net.time4j/time4j-range
ZonalDateTime zdt = ZonalDateTime.parse(parts[1], momentFormatter(extended));
Duration<?> duration = Duration.parsePeriod(parts[2]);
recurrence = IsoRecurrence.of(count, zdt.toMoment(), duration, zdt.getOffset());
} else if (parts[1].charAt(0) == 'P') {
Duration<?> duration = Duration.parsePeriod(parts[1]);
boolean extended = isExtendedFormat(parts[2]);
ZonalDateTime zdt = ZonalDateTime.parse(parts[2], momentFormatter(extended));
recurrence = IsoRecurrence.of(count, duration, zdt.toMoment(), zdt.getOffset());
} else {
String remainder = iso.substring(getFirstSlash(iso) + 1);
代码示例来源:origin: net.time4j/time4j-core
if (this.isLeapSecond()) {
sb.append("60");
} else {
PlainTime.printNanos(sb, n);
sb.append(this.getOffset());
TZID tzid = this.getTimezone();
boolean offset = (tzid instanceof ZonalOffset);
代码示例来源:origin: net.time4j/time4j-core
@Override
public Calendar from(ZonalDateTime time4j) {
Date jud = TemporalType.JAVA_UTIL_DATE.from(time4j.toMoment());
TimeZone tz = TemporalType.JAVA_UTIL_TIMEZONE.from(time4j.getTimezone0());
GregorianCalendar gcal = new GregorianCalendar();
gcal.setGregorianChange(new Date(Long.MIN_VALUE)); // proleptic gregorian
gcal.setFirstDayOfWeek(Calendar.MONDAY); // keeping ISO-8601-semantic
gcal.setMinimalDaysInFirstWeek(4); // keeping ISO-8601-semantic
gcal.setTimeZone(tz);
gcal.setTime(jud);
return gcal;
}
代码示例来源:origin: net.time4j/time4j-core
throw new ParseException("Cannot parse: " + text, pos.getErrorIndex());
} else if (rawValues.get().hasTimezone()) {
tz = toTimezone(rawValues.get().getTimezone(), text);
} else if (parser.getAttributes().contains(TIMEZONE_ID)) {
tz = toTimezone(parser.getAttributes().get(TIMEZONE_ID), text);
} else {
throw new ParseException("Missing timezone: " + text, 0);
return ZonalDateTime.of(moment, tz);
代码示例来源:origin: net.time4j/time4j-core
ZonalDateTime.class, realPattern, this.locale, this.leniency, this.tzid);
ZonalDateTime zdt = stf.parseInternal(text, position, wantsException, rawValues);
result = ((zdt == null) ? null : zdt.toMoment());
} else if (this.type.equals(ZonalDateTime.class)) {
String timezone = (
代码示例来源:origin: net.time4j/time4j-core
/**
* <p>Creates a formatted output of this instance. </p>
*
* @param printer helps to format this instance
* @return formatted string
* @since 3.0
*/
/*[deutsch]
* <p>Erzeugt eine formatierte Ausgabe dieser Instanz. </p>
*
* @param printer helps to format this instance
* @return formatted string
* @since 3.0
*/
public String print(TemporalFormatter<Moment> printer) {
return printer.withTimezone(this.getTimezone()).format(this.moment);
}
代码示例来源:origin: net.time4j/time4j-core
} else if (this.type.equals(ZonalDateTime.class)) {
ZonalDateTime zdt = ZonalDateTime.class.cast(formattable);
Moment moment = zdt.toMoment();
Date jud = TemporalType.JAVA_UTIL_DATE.from(moment);
String timezone = (
this.tzid == null
? zdt.getTimezone().canonical()
: this.tzid);
Timezone tz = Timezone.of(timezone);
代码示例来源:origin: net.time4j/time4j-core
@Override
public ZonalDateTime translate(Calendar source) {
Moment m = TemporalType.JAVA_UTIL_DATE.translate(source.getTime());
Timezone tz = TemporalType.JAVA_UTIL_TIMEZONE.translate(source.getTimeZone());
return ZonalDateTime.of(m, tz);
}
代码示例来源:origin: net.time4j/time4j-core
/**
* <p>Erzeugt einen zonalen Moment. </p>
*
* @param moment global timestamp
* @param tz timezone
* @return ZonalDateTime
* @throws IllegalArgumentException if leapsecond shall be formatted
* with non-full-minute-timezone-offset
*/
static ZonalDateTime of(
Moment moment,
Timezone tz
) {
return new ZonalDateTime(moment, tz);
}
代码示例来源:origin: net.time4j/time4j-core
/**
* <p>Creates a combination of this moment and system timezone. </p>
*
* <p>A direct conversion to a local timestamp can be achieved by
* {@link #toLocalTimestamp()}. </p>
*
* @return moment in system timezone
* @since 2.0
* @throws IllegalArgumentException if this moment is a leapsecond and
* shall be combined with a non-full-minute-timezone-offset
*/
/*[deutsch]
* <p>Erzeugt eine Kombination dieses Moments und der Systemzeitzone. </p>
*
* <p>Eine Direktumwandlung zu einem lokalen Zeitstempel kann mit Hilfe
* von {@link #toLocalTimestamp()} erreicht werden. </p>
*
* @return moment in system timezone
* @since 2.0
* @throws IllegalArgumentException if this moment is a leapsecond and
* shall be combined with a non-full-minute-timezone-offset
*/
public ZonalDateTime inLocalView() {
return ZonalDateTime.of(this, Timezone.ofSystem());
}
代码示例来源:origin: net.time4j/time4j-core
/**
* <p>This is the reverse operation of {@link #write(ObjectOutput)}. </p>
*
* @param input object input
* @return reconstructed instance of serialized {@code ZonalDateTime}
* @throws IOException if reading fails
* @throws ClassNotFoundException if class-loading fails
* @throws IllegalArgumentException in case of inconsistent data
* @since 3.1
*/
/*[deutsch]
* <p>Das ist die Umkehroperation zu {@link #write(ObjectOutput)}. </p>
*
* @param input object input
* @return reconstructed instance of serialized {@code ZonalDateTime}
* @throws IOException if reading fails
* @throws ClassNotFoundException if class-loading fails
* @throws IllegalArgumentException in case of inconsistent data
* @since 3.1
*/
public static ZonalDateTime read(ObjectInput input) throws IOException, ClassNotFoundException {
Moment moment = (Moment) input.readObject();
Timezone tz = (Timezone) input.readObject();
return new ZonalDateTime(moment, tz);
}
代码示例来源:origin: net.time4j/time4j-core
/**
* <p>Creates a combination of this moment and given timezone. </p>
*
* <p>A direct conversion to a zonal timestamp can be achieved by
* {@link #toZonalTimestamp(String)}. </p>
*
* @param tzid timezone id
* @return moment in given timezone
* @since 2.0
* @throws IllegalArgumentException if this moment is a leapsecond and
* shall be combined with a non-full-minute-timezone-offset or
* if given timezone cannot be loaded
*/
/*[deutsch]
* <p>Erzeugt eine Kombination dieses Moments und der angegebenen
* Zeitzone. </p>
*
* <p>Eine Direktumwandlung zu einem zonalen Zeitstempel kann mit Hilfe
* von {@link #toZonalTimestamp(String)} erreicht werden. </p>
*
* @param tzid timezone id
* @return moment in given timezone
* @since 2.0
* @throws IllegalArgumentException if this moment is a leapsecond and
* shall be combined with a non-full-minute-timezone-offset or
* if given timezone cannot be loaded
*/
public ZonalDateTime inZonalView(String tzid) {
return ZonalDateTime.of(this, Timezone.of(tzid));
}
代码示例来源:origin: net.time4j/time4j-core
/**
* <p>Creates a combination of this moment and given timezone. </p>
*
* <p>A direct conversion to a zonal timestamp can be achieved by
* {@link #toZonalTimestamp(TZID)}. </p>
*
* @param tzid timezone id
* @return moment in given timezone
* @since 2.0
* @throws IllegalArgumentException if this moment is a leapsecond and
* shall be combined with a non-full-minute-timezone-offset or
* if given timezone cannot be loaded
*/
/*[deutsch]
* <p>Erzeugt eine Kombination dieses Moments und der angegebenen
* Zeitzone. </p>
*
* <p>Eine Direktumwandlung zu einem zonalen Zeitstempel kann mit Hilfe
* von {@link #toZonalTimestamp(TZID)} erreicht werden. </p>
*
* @param tzid timezone id
* @return moment in given timezone
* @since 2.0
* @throws IllegalArgumentException if this moment is a leapsecond and
* shall be combined with a non-full-minute-timezone-offset or
* if given timezone cannot be loaded
*/
public ZonalDateTime inZonalView(TZID tzid) {
return ZonalDateTime.of(this, Timezone.of(tzid));
}
代码示例来源:origin: net.time4j/time4j-core
return ZonalDateTime.of(moment, tz);
内容来源于网络,如有侵权,请联系作者删除!