本文整理汇总了Java中java.time.chrono.ChronoZonedDateTime类的典型用法代码示例。如果您正苦于以下问题:Java ChronoZonedDateTime类的具体用法?Java ChronoZonedDateTime怎么用?Java ChronoZonedDateTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChronoZonedDateTime类属于java.time.chrono包,在下文中一共展示了ChronoZonedDateTime类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_MinguoDate
import java.time.chrono.ChronoZonedDateTime; //导入依赖的package包/类
@SuppressWarnings("unused")
@Test(dataProvider="samples")
public void test_MinguoDate(MinguoDate minguoDate, LocalDate iso) {
MinguoDate hd = minguoDate;
ChronoLocalDateTime<MinguoDate> hdt = hd.atTime(LocalTime.NOON);
ZoneOffset zo = ZoneOffset.ofHours(1);
ChronoZonedDateTime<MinguoDate> hzdt = hdt.atZone(zo);
hdt = hdt.plus(1, ChronoUnit.YEARS);
hdt = hdt.plus(1, ChronoUnit.MONTHS);
hdt = hdt.plus(1, ChronoUnit.DAYS);
hdt = hdt.plus(1, ChronoUnit.HOURS);
hdt = hdt.plus(1, ChronoUnit.MINUTES);
hdt = hdt.plus(1, ChronoUnit.SECONDS);
hdt = hdt.plus(1, ChronoUnit.NANOS);
ChronoLocalDateTime<MinguoDate> a2 = hzdt.toLocalDateTime();
MinguoDate a3 = a2.toLocalDate();
MinguoDate a5 = hzdt.toLocalDate();
//System.out.printf(" d: %s, dt: %s; odt: %s; zodt: %s; a4: %s%n", date, hdt, hodt, hzdt, a5);
}
示例2: test_badTemporalFieldChrono
import java.time.chrono.ChronoZonedDateTime; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badTemporalFieldChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
TemporalField adjuster = new FixedTemporalField(czdt2);
if (chrono != chrono2) {
try {
czdt.with(adjuster, 1);
Assert.fail("TemporalField doWith() should have thrown a ClassCastException, " + czdt.getClass()
+ " can not be cast to " + czdt2.getClass());
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoZonedDateTime<?> result = czdt.with(adjuster, 1);
assertEquals(result, czdt2, "TemporalField doWith() failed to replace date");
}
}
}
示例3: from
import java.time.chrono.ChronoZonedDateTime; //导入依赖的package包/类
/**
* Obtains an instance of {@code LocalTime} from a date-time object.
* <p>
* A {@code DateTimeAccessor} represents some form of date and time information. This factory converts the
* arbitrary date-time object to an instance of {@code LocalTime}.
* <p>
* The conversion extracts the {@link ChronoField#NANO_OF_DAY nano-of-day} field.
*
* @param dateTime the date-time object to convert, not null
* @return the local time, not null
* @throws DateTimeException if unable to convert to a {@code LocalTime}
*/
public static LocalTime from(DateTimeAccessor dateTime) {
if (dateTime instanceof LocalTime) {
return (LocalTime) dateTime;
} else if (dateTime instanceof ChronoLocalDateTime) {
return ((ChronoLocalDateTime<?>) dateTime).getTime();
} else if (dateTime instanceof ZonedDateTime) {
return ((ChronoZonedDateTime<?>) dateTime).getTime();
}
// handle builder as a special case
if (dateTime instanceof DateTimeBuilder) {
DateTimeBuilder builder = (DateTimeBuilder) dateTime;
LocalTime time = builder.extract(LocalTime.class);
if (time != null) {
return time;
}
}
return ofNanoOfDay(dateTime.getLong(NANO_OF_DAY));
}
示例4: compareTo
import java.time.chrono.ChronoZonedDateTime; //导入依赖的package包/类
@Override
public int compareTo(ChronoZonedDateTime<?> other) {
int cmp = Jdk7Methods.Long_compare(toEpochSecond(), other.toEpochSecond());
if (cmp == 0) {
cmp = getTime().getNano() - other.getTime().getNano();
if (cmp == 0) {
cmp = getDateTime().compareTo(other.getDateTime());
if (cmp == 0) {
cmp = getZone().getId().compareTo(other.getZone().getId());
if (cmp == 0) {
cmp = getDate().getChrono().compareTo(other.getDate().getChrono());
}
}
}
}
return cmp;
}
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:19,代码来源:DefaultInterfaceChronoZonedDateTime.java
示例5: test_badWithAdjusterChrono
import java.time.chrono.ChronoZonedDateTime; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badWithAdjusterChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
TemporalAdjuster adjuster = new FixedAdjuster(czdt2);
if (chrono != chrono2) {
try {
czdt.with(adjuster);
Assert.fail("WithAdjuster should have thrown a ClassCastException, "
+ "required: " + czdt + ", supplied: " + czdt2);
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
ChronoZonedDateTime<?> result = czdt.with(adjuster);
assertEquals(result, czdt2, "WithAdjuster failed to replace date");
}
}
}
示例6: test_badPlusAdjusterChrono
import java.time.chrono.ChronoZonedDateTime; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badPlusAdjusterChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
TemporalAmount adjuster = new FixedAdjuster(czdt2);
if (chrono != chrono2) {
try {
czdt.plus(adjuster);
Assert.fail("WithAdjuster should have thrown a ClassCastException, "
+ "required: " + czdt + ", supplied: " + czdt2);
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoZonedDateTime<?> result = czdt.plus(adjuster);
assertEquals(result, czdt2, "WithAdjuster failed to replace date time");
}
}
}
示例7: test_badMinusAdjusterChrono
import java.time.chrono.ChronoZonedDateTime; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badMinusAdjusterChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
TemporalAmount adjuster = new FixedAdjuster(czdt2);
if (chrono != chrono2) {
try {
czdt.minus(adjuster);
Assert.fail("WithAdjuster should have thrown a ClassCastException, "
+ "required: " + czdt + ", supplied: " + czdt2);
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoZonedDateTime<?> result = czdt.minus(adjuster);
assertEquals(result, czdt2, "WithAdjuster failed to replace date");
}
}
}
示例8: test_badPlusTemporalUnitChrono
import java.time.chrono.ChronoZonedDateTime; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
TemporalUnit adjuster = new FixedTemporalUnit(czdt2);
if (chrono != chrono2) {
try {
czdt.plus(1, adjuster);
Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException, " + czdt
+ " can not be cast to " + czdt2);
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoZonedDateTime<?> result = czdt.plus(1, adjuster);
assertEquals(result, czdt2, "WithAdjuster failed to replace date");
}
}
}
示例9: test_badMinusTemporalUnitChrono
import java.time.chrono.ChronoZonedDateTime; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badMinusTemporalUnitChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
TemporalUnit adjuster = new FixedTemporalUnit(czdt2);
if (chrono != chrono2) {
try {
czdt.minus(1, adjuster);
Assert.fail("TemporalUnit.doPlus minus should have thrown a ClassCastException, " + czdt.getClass()
+ " can not be cast to " + czdt2.getClass());
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoZonedDateTime<?> result = czdt.minus(1, adjuster);
assertEquals(result, czdt2, "WithAdjuster failed to replace date");
}
}
}
示例10: testZoneId
import java.time.chrono.ChronoZonedDateTime; //导入依赖的package包/类
private void testZoneId(Locale locale, ChronoZonedDateTime<?> zdt, Calendar cal) {
String fmtStr = "z:[%tz] z:[%1$Tz] Z:[%1$tZ] Z:[%1$TZ]";
printFmtStr(locale, fmtStr);
String expected = toZoneIdStr(test(fmtStr, locale, null, cal));
test(fmtStr, locale, expected, zdt);
// get a new cal with fixed tz
Calendar cal0 = Calendar.getInstance();
cal0.setTimeInMillis(zdt.toInstant().toEpochMilli());
cal0.setTimeZone(TimeZone.getTimeZone("GMT" + zdt.getOffset().getId()));
expected = toZoneOffsetStr(test(fmtStr, locale, null, cal0));
if (zdt instanceof ZonedDateTime) {
OffsetDateTime odt = ((ZonedDateTime)zdt).toOffsetDateTime();
test(fmtStr, locale, expected, odt);
test(fmtStr, locale, expected, odt.toOffsetTime());
}
// datetime + zid
fmtStr = "c:[%tc] c:[%1$Tc]";
printFmtStr(locale, fmtStr);
expected = toZoneIdStr(test(fmtStr, locale, null, cal));
test(fmtStr, locale, expected, zdt);
}
示例11: testZoneId
import java.time.chrono.ChronoZonedDateTime; //导入依赖的package包/类
private void testZoneId(Locale locale, ChronoZonedDateTime<?> zdt, Calendar cal) {
String fmtStr = "z:[%tz] z:[%1$Tz] Z:[%1$tZ] Z:[%1$TZ]";
printFmtStr(locale, fmtStr);
String expected = test(fmtStr, locale, null, cal);
test(fmtStr, locale, expected, zdt);
// get a new cal with fixed tz
Calendar cal0 = Calendar.getInstance();
cal0.setTimeInMillis(zdt.toInstant().toEpochMilli());
cal0.setTimeZone(TimeZone.getTimeZone("GMT" + zdt.getOffset().getId()));
expected = toZoneOffsetStr(test(fmtStr, locale, null, cal0));
if (zdt instanceof ZonedDateTime) {
OffsetDateTime odt = ((ZonedDateTime)zdt).toOffsetDateTime();
test(fmtStr, locale, expected, odt);
test(fmtStr, locale, expected, odt.toOffsetTime());
}
// datetime + zid
fmtStr = "c:[%tc] c:[%1$Tc]";
printFmtStr(locale, fmtStr);
expected = test(fmtStr, locale, null, cal);
test(fmtStr, locale, expected, zdt);
}