本文整理汇总了Java中java.time.calendrical.DateTimeBuilder.extract方法的典型用法代码示例。如果您正苦于以下问题:Java DateTimeBuilder.extract方法的具体用法?Java DateTimeBuilder.extract怎么用?Java DateTimeBuilder.extract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.calendrical.DateTimeBuilder
的用法示例。
在下文中一共展示了DateTimeBuilder.extract方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: from
import java.time.calendrical.DateTimeBuilder; //导入方法依赖的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));
}
示例2: from
import java.time.calendrical.DateTimeBuilder; //导入方法依赖的package包/类
/**
* Obtains an instance of {@code LocalDate} 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 LocalDate}.
* <p>
* The conversion extracts the {@link ChronoField#EPOCH_DAY epoch-day} field.
*
* @param dateTime the date-time object to convert, not null
* @return the local date, not null
* @throws DateTimeException if unable to convert to a {@code LocalDate}
*/
public static LocalDate from(DateTimeAccessor dateTime) {
if (dateTime instanceof LocalDate) {
return (LocalDate) dateTime;
} else if (dateTime instanceof LocalDateTime) {
return ((LocalDateTime) dateTime).getDate();
} else if (dateTime instanceof ZonedDateTime) {
return ((ZonedDateTime) dateTime).getDate();
}
// handle builder as a special case
if (dateTime instanceof DateTimeBuilder) {
DateTimeBuilder builder = (DateTimeBuilder) dateTime;
LocalDate date = builder.extract(LocalDate.class);
if (date != null) {
return date;
}
}
return ofEpochDay(dateTime.getLong(EPOCH_DAY));
}