本文整理汇总了Java中java.time.chrono.ChronoLocalDateTime类的典型用法代码示例。如果您正苦于以下问题:Java ChronoLocalDateTime类的具体用法?Java ChronoLocalDateTime怎么用?Java ChronoLocalDateTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChronoLocalDateTime类属于java.time.chrono包,在下文中一共展示了ChronoLocalDateTime类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_MinguoDate
import java.time.chrono.ChronoLocalDateTime; //导入依赖的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: from
import java.time.chrono.ChronoLocalDateTime; //导入依赖的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));
}
示例3: test_badWithAdjusterChrono
import java.time.chrono.ChronoLocalDateTime; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badWithAdjusterChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
TemporalAdjuster adjuster = new FixedAdjuster(cdt2);
if (chrono != chrono2) {
try {
cdt.with(adjuster);
Assert.fail("WithAdjuster should have thrown a ClassCastException, "
+ "required: " + cdt + ", supplied: " + cdt2);
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoLocalDateTime<?> result = cdt.with(adjuster);
assertEquals(result, cdt2, "WithAdjuster failed to replace date");
}
}
}
示例4: test_badPlusAdjusterChrono
import java.time.chrono.ChronoLocalDateTime; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badPlusAdjusterChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
TemporalAmount adjuster = new FixedAdjuster(cdt2);
if (chrono != chrono2) {
try {
cdt.plus(adjuster);
Assert.fail("WithAdjuster should have thrown a ClassCastException, "
+ "required: " + cdt + ", supplied: " + cdt2);
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoLocalDateTime<?> result = cdt.plus(adjuster);
assertEquals(result, cdt2, "WithAdjuster failed to replace date time");
}
}
}
示例5: test_badMinusAdjusterChrono
import java.time.chrono.ChronoLocalDateTime; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badMinusAdjusterChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
TemporalAmount adjuster = new FixedAdjuster(cdt2);
if (chrono != chrono2) {
try {
cdt.minus(adjuster);
Assert.fail("WithAdjuster should have thrown a ClassCastException, "
+ "required: " + cdt + ", supplied: " + cdt2);
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoLocalDateTime<?> result = cdt.minus(adjuster);
assertEquals(result, cdt2, "WithAdjuster failed to replace date");
}
}
}
示例6: test_badPlusTemporalUnitChrono
import java.time.chrono.ChronoLocalDateTime; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
TemporalUnit adjuster = new FixedTemporalUnit(cdt2);
if (chrono != chrono2) {
try {
cdt.plus(1, adjuster);
Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException" + cdt
+ ", can not be cast to " + cdt2);
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoLocalDateTime<?> result = cdt.plus(1, adjuster);
assertEquals(result, cdt2, "WithAdjuster failed to replace date");
}
}
}
示例7: test_badMinusTemporalUnitChrono
import java.time.chrono.ChronoLocalDateTime; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badMinusTemporalUnitChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
TemporalUnit adjuster = new FixedTemporalUnit(cdt2);
if (chrono != chrono2) {
try {
cdt.minus(1, adjuster);
Assert.fail("TemporalUnit.doPlus minus should have thrown a ClassCastException" + cdt.getClass()
+ ", can not be cast to " + cdt2.getClass());
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoLocalDateTime<?> result = cdt.minus(1, adjuster);
assertEquals(result, cdt2, "WithAdjuster failed to replace date");
}
}
}
示例8: test_badTemporalFieldChrono
import java.time.chrono.ChronoLocalDateTime; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badTemporalFieldChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
TemporalField adjuster = new FixedTemporalField(cdt2);
if (chrono != chrono2) {
try {
cdt.with(adjuster, 1);
Assert.fail("TemporalField doWith() should have thrown a ClassCastException" + cdt.getClass()
+ ", can not be cast to " + cdt2.getClass());
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoLocalDateTime<?> result = cdt.with(adjuster, 1);
assertEquals(result, cdt2, "TemporalField doWith() failed to replace date");
}
}
}
示例9: compareTo
import java.time.chrono.ChronoLocalDateTime; //导入依赖的package包/类
@Override
public int compareTo(ChronoLocalDateTime<?> other) {
int cmp = getDate().compareTo(other.getDate());
if (cmp == 0) {
cmp = getTime().compareTo(other.getTime());
if (cmp == 0) {
cmp = getDate().getChrono().compareTo(other.getDate().getChrono());
}
}
return cmp;
}
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:13,代码来源:DefaultInterfaceChronoLocalDateTime.java
示例10: isAfter
import java.time.chrono.ChronoLocalDateTime; //导入依赖的package包/类
@Override
public boolean isAfter(ChronoLocalDateTime<?> other) {
long thisEpDay = getDate().toEpochDay();
long otherEpDay = other.getDate().toEpochDay();
return thisEpDay > otherEpDay
|| (thisEpDay == otherEpDay && getTime().toNanoOfDay() > other.getTime().toNanoOfDay());
}
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:9,代码来源:DefaultInterfaceChronoLocalDateTime.java
示例11: isBefore
import java.time.chrono.ChronoLocalDateTime; //导入依赖的package包/类
@Override
public boolean isBefore(ChronoLocalDateTime<?> other) {
long thisEpDay = getDate().toEpochDay();
long otherEpDay = other.getDate().toEpochDay();
return thisEpDay < otherEpDay
|| (thisEpDay == otherEpDay && getTime().toNanoOfDay() < other.getTime().toNanoOfDay());
}
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:9,代码来源:DefaultInterfaceChronoLocalDateTime.java
示例12: isEqual
import java.time.chrono.ChronoLocalDateTime; //导入依赖的package包/类
@Override
public boolean isEqual(ChronoLocalDateTime<?> other) {
// Do the time check first, it is cheaper than computing EPOCH day.
return getTime().toNanoOfDay() == other.getTime().toNanoOfDay()
&& getDate().toEpochDay() == other.getDate().toEpochDay();
}
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:8,代码来源:DefaultInterfaceChronoLocalDateTime.java
示例13: equals
import java.time.chrono.ChronoLocalDateTime; //导入依赖的package包/类
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof ChronoLocalDateTime) {
return compareTo((ChronoLocalDateTime<?>) obj) == 0;
}
return false;
}
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:12,代码来源:DefaultInterfaceChronoLocalDateTime.java