当前位置: 首页>>代码示例>>Java>>正文


Java DateTimeBuilder.extract方法代码示例

本文整理汇总了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));
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:32,代码来源:LocalTime.java

示例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));
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:32,代码来源:LocalDate.java


注:本文中的java.time.calendrical.DateTimeBuilder.extract方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。